public void Dispose_CalledMoreThanOnce_DoesNotThrow()
 {
     using (var staticMock = new StaticMock(typeof(TargetNamespace.TargetClass)))
     {
         Assert.DoesNotThrow(() => staticMock.Dispose());
     }
 }
        public object StaticMock_For_NoReturns()
        {
            using (var staticMock = new StaticMock(typeof(Program)))
            {
                staticMock.For(() => System.IO.File.ReadAllText("foo"));

                return(Program.Read("foo"));
            }
        }
        public object StaticMock_Setup()
        {
            using (var staticMock = new StaticMock(typeof(Program)))
            {
                staticMock.Setup(() => System.IO.File.ReadAllText("foo")).Returns("bar");

                return(Program.Read("foo"));
            }
        }
        public void GetMockDelegate_DelegateType_IsFuncInt()
        {
            using (var staticMock = new StaticMock(typeof(TargetNamespace.TargetClass)))
            {
                var method = new Func <int>(StaticNamespace.StaticClass.FuncInt).GetMethodInfo();

                var mockDelegate = staticMock.GetMockDelegate(method);

                Assert.That(mockDelegate.DelegateType, Is.EqualTo(typeof(Func <int>)));
            }
        }
        public void GetMockDelegate_IsMocked_IsFalse()
        {
            using (var staticMock = new StaticMock(typeof(TargetNamespace.TargetClass)))
            {
                var method = new Func <int>(StaticNamespace.StaticClass.FuncInt).GetMethodInfo();

                var mockDelegate = staticMock.GetMockDelegate(method);

                Assert.That(mockDelegate.IsMocked, Is.False);
            }
        }
Exemple #6
0
    public void MockStaticDefaultThrowsForAll()
    {
        using (var staticMock = new StaticMock(typeof(ClassUsesFile)))
        {
            staticMock.For(() => File.ReadAllText("foo.txt")).Returns("bar");
            staticMock.ThrowsForAll(new FileNotFoundException());

            Assert.That(ClassUsesFile.ShoutFile("foo.txt"), Is.EqualTo("BAR"));
            Assert.Throws <FileNotFoundException>(() => ClassUsesFile.ShoutFile("boom.txt"));
        }
    }
Exemple #7
0
    public void MockStaticFunction()
    {
        using (var staticMock = new StaticMock(typeof(ClassUsesFile)))
        {
            staticMock.For(() => File.ReadAllText("foo.txt")).Returns("bar");

            var text = ClassUsesFile.ShoutFile("foo.txt");

            Assert.That(text, Is.EqualTo("BAR"));
        }
    }
Exemple #8
0
    public void ValidateStaticAction()
    {
        using (var staticMock = new StaticMock(typeof(ClassUsesConsole)))
        {
            var text = "Hello, World!";
            staticMock.For(() => Console.WriteLine(Arg.Any <string>()));

            ClassUsesConsole.WriteLine(text);

            staticMock.Received(1, () => Console.WriteLine(text));
        }
    }
        public void For_StaticMockCollision_ThrowsException()
        {
            var targetType    = GetType();
            var expectMessage = StaticMockException.AlreadyActiveMessage(targetType);

            var ex = Assert.Throws <StaticMockException>(() =>
            {
                using (var staticMock2 = new StaticMock(targetType)) { }
            });

            Assert.That(ex.Message, Is.EqualTo(expectMessage));
        }
Exemple #10
0
    public void MockStaticDefaultThrows()
    {
        using (var staticMock = new StaticMock(typeof(ClassUsesFile)))
        {
            staticMock.For(() => File.ReadAllText(null)).ReturnsForAnyArgs(x =>
            {
                switch (x.ArgAt <string>(0))
                {
                case "foo.txt":
                    return("bar");

                default:
                    throw new FileNotFoundException();
                }
            });

            Assert.That(ClassUsesFile.ShoutFile("foo.txt"), Is.EqualTo("BAR"));
            Assert.Throws <FileNotFoundException>(() => ClassUsesFile.ShoutFile("boom.txt"));
        }
    }
 public void SetUp()
 {
     staticMock = new StaticMock(typeof(GhostAssemblyLoader));
 }
 public void SetUp()
 {
     staticMock = new StaticMock(GetType());
 }