Comments (4)
You probably should only include the Nuget and replacement in your test project. In most cases I declare the replacement in my Test class unless I find myself duplicating the code.
from ionad.
As @MNF I also think this must be clarified.
If I create a DateTime substitute class on another namespace related (and used) on my test class, DateTime is not substituted.
If I declare it on the same namespace (but another assembly) It is not substituted either.
from ionad.
In example:
On this code:
- Test
a
does not pass. - But test
b
is passing (green)
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FodyIonadConsoleApp;
namespace FodyIonadLibraryTests
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void a()
{
DateTimeSubstitute.Current = new DateTime(2000, 01, 01, 00, 00, 00);
var sut = new DateComparer();
var result = sut.Compare(new DateTime(2000, 01, 01, 00, 05, 00));
Assert.AreEqual(5, result);
}
[TestMethod]
public void b()
{
var result = DateTime.Now;
Assert.AreEqual(2000, result.Year);
}
}
}
With this DateComparer
simple class:
using System;
namespace FodyIonadConsoleApp
{
public class DateComparer
{
public double Compare(DateTime dateToCompare)
{
return (DateTime.Now - dateToCompare).TotalMinutes;
}
}
}
And with the sample StaticReplacement
example:
using Ionad;
using System;
namespace FodyIonadLibraryTests
{
[StaticReplacement(typeof(DateTime))]
public static class DateTimeSubstitute
{
public static DateTime Current { get; set; }
public static DateTime Now { get { return Current; } }
}
}
What is wrong here?
from ionad.
closing this as stale. if it is still an problem please raise a new issue
from ionad.
Related Issues (10)
- Weave to-be-test dll in unit test project HOT 18
- Doe this work for Static Method HOT 1
- Is it possible to run Ionad on-demand? HOT 6
- Unable to weave async/await HOT 3
- Ionad does not support method overloading HOT 6
- Update to Fody Version 2
- Ionad does not support decoration of static methods
- Update to Fody 6
- Update to Fody 3.0
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ionad.