Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GetByIdTests : BaseTest
- {
- protected Mock<IProductRepository> Repository { get; private set; }
- protected ProductLogic Create()
- {
- Repository = new Mock<IProductRepository>();
- return new ProductLogic(new Lazy<IProductRepository>(() => Repository.Object));
- }
- [Fact]
- public void Return_Product_From_Repository()
- {
- var logic = Create();
- var product = Builder<Product>.CreateNew().Build();
- Repository.Setup(r => r.GetById(It.IsAny<int>()))
- .Returns(product);
- var result = logic.GetById(10);
- Assert.NotNull(result);
- Assert.True(result.Success);
- Assert.Equal(product, result.Value);
- Assert.NotNull(result.Errors);
- Assert.Equal(0, result.Errors.Count());
- Repository.Verify(r => r.GetById(10), Times.Once());
- }
- [Fact]
- public void Return_Error_When_Product_Not_Exist()
- {
- var logic = Create();
- Repository.Setup(r => r.GetById(It.IsAny<int>()))
- .Returns((Product)null);
- var result = logic.GetById(10);
- Assert.NotNull(result);
- Assert.False(result.Success);
- Assert.Null(result.Value);
- Assert.NotNull(result.Errors);
- Assert.Equal(1, result.Errors.Count());
- var error = result.Errors.First();
- Assert.Equal(string.Empty, error.PropertyName);
- Assert.Equal("Nie ma produktu o id 10.", error.Message);
- Repository.Verify(r => r.GetById(10), Times.Once());
- }
- }
Add Comment
Please, Sign In to add comment