public void AddNewSoftwareThrowExceptionWhenDataIsInvalid() { //Arrange var customerRepository = new Mock <ICustomerRepository>(); var productRepository = new Mock <IProductRepository>(); var orderRepository = new Mock <IOrderRepository>(); Mock <ILogger <SalesAppService> > _mockLogger = new Mock <ILogger <SalesAppService> >(); var salesManagement = new SalesAppService(productRepository.Object, orderRepository.Object, customerRepository.Object, _mockLogger.Object); var dto = new SoftwareDTO() { Title = "The title", Description = "the description", LicenseCode = "license", AmountInStock = 10, UnitPrice = -1//this is a not valid value }; Exception ex = Assert.Throws <ApplicationValidationErrorsException>(() => { //Act var result = salesManagement.AddNewSoftware(dto); } ); Assert.IsType(typeof(ApplicationValidationErrorsException), ex); }
public void AddNewSoftwareWithNullDataThrowArgumentException() { //Arrange var customerRepository = new SICustomerRepository(); var productRepository = new SIProductRepository(); var orderRepository = new SIOrderRepository(); var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository); //Act var result = salesManagement.AddNewSoftware(null); }
public void AddNewSoftwareWithNullDataThrowArgumentException() { //Arrange var customerRepository = new Mock <ICustomerRepository>(); var productRepository = new Mock <IProductRepository>(); var orderRepository = new Mock <IOrderRepository>(); Mock <ILogger <SalesAppService> > _mockLogger = new Mock <ILogger <SalesAppService> >(); var salesManagement = new SalesAppService(productRepository.Object, orderRepository.Object, customerRepository.Object, _mockLogger.Object); Exception ex = Assert.Throws <ArgumentException>(() => { //Act var result = salesManagement.AddNewSoftware(null); } ); Assert.IsType(typeof(ArgumentException), ex); }
public void AddNewSoftwareReturnAddedSoftware() { //Arrange var customerRepository = new Mock <ICustomerRepository>(); var orderRepository = new Mock <IOrderRepository>(); var productRepository = new Mock <IProductRepository>(); Mock <MainBCUnitOfWork> _mockContext = new Mock <MainBCUnitOfWork>(); _mockContext.Setup(c => c.Commit()); productRepository.Setup(x => x.Add(It.IsAny <Product>())); productRepository .Setup(x => x.UnitOfWork).Returns(_mockContext.Object); Mock <ILogger <SalesAppService> > _mockLogger = new Mock <ILogger <SalesAppService> >(); var salesManagement = new SalesAppService(productRepository.Object, orderRepository.Object, customerRepository.Object, _mockLogger.Object); var dto = new SoftwareDTO() { Title = "The title", Description = "description", LicenseCode = "license code", AmountInStock = 10, UnitPrice = 10 }; //Act var result = salesManagement.AddNewSoftware(dto); //Assert Assert.NotNull(result); Assert.True(result.Id != Guid.Empty); Assert.Equal(result.Title, dto.Title); Assert.Equal(result.Description, dto.Description); Assert.Equal(result.LicenseCode, dto.LicenseCode); Assert.Equal(result.AmountInStock, dto.AmountInStock); Assert.Equal(result.UnitPrice, dto.UnitPrice); }
public void AddNewSoftwareReturnAddedSoftware() { //Arrange var customerRepository = new SICustomerRepository(); var orderRepository = new SIOrderRepository(); var productRepository = new SIProductRepository(); productRepository.UnitOfWorkGet = () => { var uow = new SIUnitOfWork(); uow.Commit = () => { }; return(uow); }; productRepository.AddProduct = (product) => { }; var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository); var dto = new SoftwareDTO() { Title = "The title", Description = "description", LicenseCode = "license code", AmountInStock = 10, UnitPrice = 10 }; //Act var result = salesManagement.AddNewSoftware(dto); //Assert Assert.IsNotNull(result); Assert.IsTrue(result.Id != Guid.Empty); Assert.AreEqual(result.Title, dto.Title); Assert.AreEqual(result.Description, dto.Description); Assert.AreEqual(result.LicenseCode, dto.LicenseCode); Assert.AreEqual(result.AmountInStock, dto.AmountInStock); Assert.AreEqual(result.UnitPrice, dto.UnitPrice); }
public void AddNewSoftwareThrowExceptionWhenDataIsInvalid() { //Arrange var customerRepository = new SICustomerRepository(); var productRepository = new SIProductRepository(); var orderRepository = new SIOrderRepository(); var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository); var dto = new SoftwareDTO() { Title = "The title", Description = "the description", LicenseCode = "license", AmountInStock = 10, UnitPrice = -1//this is a not valid value }; //Act var result = salesManagement.AddNewSoftware(dto); }