示例#1
0
        public async Task ReadAll_Test()
        {
            // arrange
            var fakeUowProvider  = A.Fake <IUnitOfWorkProvider>();
            var fakeRepoProvider = A.Fake <IBookCopyRepositoryProvider>();
            var fakeRepo         = A.Fake <IBookCopyRepository>();
            var fakeUow          = A.Fake <IUnitOfWork>();

            A.CallTo(() => fakeUowProvider.Get()).Returns(fakeUow);
            A.CallTo(() => fakeRepoProvider.Get(fakeUow)).Returns(fakeRepo);
            BookCopyService service = new BookCopyService(fakeUowProvider, fakeRepoProvider);
            List <BookCopy> copies  = new List <BookCopy>
            {
                new BookCopy {
                    Id = 1, BookId = 1, Description = "copy", Notes = "copy"
                }
            };

            A.CallTo(() => fakeRepo.ReadAll()).Returns(copies);

            // act
            var result = await service.GetAll();

            // assert
            Assert.IsTrue(result.ToList().Count == 1);
            Assert.IsTrue(result.ToList()[0].Id == 1);
            Assert.IsTrue(result.ToList()[0].BookId == 1);
            Assert.IsTrue(result.ToList()[0].Description.Equals("copy"));
            Assert.IsTrue(result.ToList()[0].Notes.Equals("copy"));
            A.CallTo(() => fakeUow.Dispose()).MustHaveHappened();
        }