public void BasicMocking()
        {
            var mock = new Mock<IFileHelperEngine<SampleType>>();
            mock.Setup(x => x.ReadFile(It.IsAny<string>()))
                .Returns(new[]
                             {
                                 new SampleType {Field1 = new DateTime(2010, 3, 2), Field2 = "field2.1", Field3 = 1},
                                 new SampleType {Field1 = new DateTime(2010, 4, 5), Field2 = "field2.2", Field3 = 2},
                                 new SampleType {Field1 = new DateTime(2010, 6, 7), Field2 = "field2.3", Field3 = 3}
                             });

            var client = new FileHelpersClient(mock.Object);

            client.WorkWithFiles();

            client.DataInFile.Length.AssertEqualTo(3);

            client.Status.AssertEqualTo(ClientStatus.Ok);
            client.DataInFile[0].Field1.AssertEqualTo(new DateTime(2010, 3, 2));
            client.DataInFile[1].Field1.AssertEqualTo(new DateTime(2010, 4, 5));
            client.DataInFile[2].Field1.AssertEqualTo(new DateTime(2010, 6, 7));

            client.DataInFile[0].Field2.AssertEqualTo("field2.1");
            client.DataInFile[1].Field2.AssertEqualTo("field2.2");
            client.DataInFile[2].Field2.AssertEqualTo("field2.3");

            client.DataInFile[0].Field3.AssertEqualTo(1);
            client.DataInFile[1].Field3.AssertEqualTo(2);
            client.DataInFile[2].Field3.AssertEqualTo(3);

            mock.VerifyAll();
        }
        public void BubblingOutOfMemory()
        {
            var mock = new Mock<IFileHelperEngine<SampleType>>();
            mock.Setup(x => x.ReadFile(It.IsAny<string>()))
                .Throws(new OutOfMemoryException());

            var client = new FileHelpersClient(mock.Object);

            Assert.Throws<OutOfMemoryException>(
                    () => client.WorkWithFiles()
                );

            mock.VerifyAll();
        }
Beispiel #3
0
        public void BubblingOutOfMemory()
        {
            var mock = new Mock <IFileHelperEngine <SampleType> >();

            mock.Setup(x => x.ReadFile(It.IsAny <string>()))
            .Throws(new OutOfMemoryException());

            var client = new FileHelpersClient(mock.Object);

            Assert.Throws <OutOfMemoryException>(
                () => client.WorkWithFiles()
                );

            mock.VerifyAll();
        }
Beispiel #4
0
        public void UnhandledExceptionAnother()
        {
            var mock = new Mock <IFileHelperEngine <SampleType> >();

            mock.Setup(x => x.ReadFile(It.IsAny <string>()))
            .Throws(new InvalidOperationException());

            var client = new FileHelpersClient(mock.Object);

            client.WorkWithFiles();

            client.Status.AssertEqualTo(ClientStatus.UnhandledError);
            client.DataInFile.AssertIsNull();

            mock.VerifyAll();
        }
Beispiel #5
0
        public void FileNotFoundException()
        {
            var mock = new Mock <IFileHelperEngine <SampleType> >();

            mock.Setup(x => x.ReadFile(It.IsAny <string>()))
            .Throws(new FileNotFoundException());

            var client = new FileHelpersClient(mock.Object);

            client.WorkWithFiles();

            client.Status.AssertEqualTo(ClientStatus.FileNotFound);
            client.DataInFile.AssertIsNull();

            mock.VerifyAll();
        }
        public void UnhandledExceptionBasic()
        {
            var mock = new Mock <IFileHelperEngine <SampleType> >();

            mock.Setup(x => x.ReadFile(It.IsAny <string>()))
            .Throws(new Exception());

            var client = new FileHelpersClient(mock.Object);

            client.WorkWithFiles();

            Check.That(client.Status).IsEqualTo(ClientStatus.UnhandledError);
            Check.That(client.DataInFile).IsNull();

            mock.VerifyAll();
        }
Beispiel #7
0
        public void BasicMocking()
        {
            var mock = new Mock <IFileHelperEngine <SampleType> >();

            mock.Setup(x => x.ReadFile(It.IsAny <string>()))
            .Returns(new[] {
                new SampleType {
                    Field1 = new DateTime(2010, 3, 2),
                    Field2 = "field2.1",
                    Field3 = 1
                },
                new SampleType {
                    Field1 = new DateTime(2010, 4, 5),
                    Field2 = "field2.2",
                    Field3 = 2
                },
                new SampleType {
                    Field1 = new DateTime(2010, 6, 7),
                    Field2 = "field2.3",
                    Field3 = 3
                }
            });

            var client = new FileHelpersClient(mock.Object);

            client.WorkWithFiles();

            client.DataInFile.Length.AssertEqualTo(3);

            client.Status.AssertEqualTo(ClientStatus.Ok);
            client.DataInFile[0].Field1.AssertEqualTo(new DateTime(2010, 3, 2));
            client.DataInFile[1].Field1.AssertEqualTo(new DateTime(2010, 4, 5));
            client.DataInFile[2].Field1.AssertEqualTo(new DateTime(2010, 6, 7));


            client.DataInFile[0].Field2.AssertEqualTo("field2.1");
            client.DataInFile[1].Field2.AssertEqualTo("field2.2");
            client.DataInFile[2].Field2.AssertEqualTo("field2.3");

            client.DataInFile[0].Field3.AssertEqualTo(1);
            client.DataInFile[1].Field3.AssertEqualTo(2);
            client.DataInFile[2].Field3.AssertEqualTo(3);

            mock.VerifyAll();
        }
        public void UnhandledExceptionAnother()
        {
            var mock = new Mock<IFileHelperEngine<SampleType>>();
            mock.Setup(x => x.ReadFile(It.IsAny<string>()))
                .Throws(new InvalidOperationException());

            var client = new FileHelpersClient(mock.Object);
            client.WorkWithFiles();

            client.Status.AssertEqualTo(ClientStatus.UnhandledError);
            client.DataInFile.AssertIsNull();

            mock.VerifyAll();
        }
        public void FileNotFoundException()
        {
            var mock = new Mock<IFileHelperEngine<SampleType>>();
            mock.Setup(x => x.ReadFile(It.IsAny<string>()))
                .Throws(new FileNotFoundException());

            var client = new FileHelpersClient(mock.Object);
            client.WorkWithFiles();

            client.Status.AssertEqualTo(ClientStatus.FileNotFound);
            client.DataInFile.AssertIsNull();

            mock.VerifyAll();
        }
        public void UnhandledExceptionBasic()
        {
            var mock = new Mock<IFileHelperEngine<SampleType>>();
            mock.Setup(x => x.ReadFile(It.IsAny<string>()))
                .Throws(new Exception());

            var client = new FileHelpersClient(mock.Object);
            client.WorkWithFiles();

            Check.That(client.Status).IsEqualTo(ClientStatus.UnhandledError);
            Check.That(client.DataInFile).IsNull();

            mock.VerifyAll();
        }