Giter Club home page Giter Club logo

Comments (4)

antarr avatar antarr commented on June 3, 2024

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.

ferpega avatar ferpega commented on June 3, 2024

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.

ferpega avatar ferpega commented on June 3, 2024

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.

SimonCropp avatar SimonCropp commented on June 3, 2024

closing this as stale. if it is still an problem please raise a new issue

from ionad.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.