public void Update_NoDataSupplied_VerifyDoesNotCallToRepository() { //arrange var vm = new XactionViewModel(); //act var result = Service.Update(vm); //Assert Assert.IsFalse(result); _dbAdaptorMock.Verify(x => x.Update(It.IsAny <Xaction>()), Times.Never); }
public void Create_ShouldSendEmail() { //arrange XactionViewModel xact = new XactionViewModel(); _dbAdaptorMock.Setup(x => x.Create(It.IsAny <Xaction>())); //act var result = Service.Create(xact); //assert _emailSenderMock.Verify(x => x.SendEmail(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once); }
public void Create_WhenTransactionAmountTooLarge_ThrowException() { //arrange var vm = new XactionViewModel(); vm.Amount = 21000.00M; vm.HouseId = 1; vm.Id = 1; vm.Description = "ddd"; //act & Assert var res = Assert.ThrowsException <ArgumentOutOfRangeException>(() => Service.Create(vm)); }
public void Create_ShouldReturnTrue() { //arrange XactionViewModel xact = new XactionViewModel(); // xactList.Add(new Xaction(2, "Test Transaction2", 1200)); _dbAdaptorMock.Setup(x => x.Create(It.IsAny <Xaction>())); //act var result = Service.Create(xact); //Assert Assert.IsTrue(result); }
public bool Create(XactionViewModel vm) { if (vm.Amount > 20000.00M) { throw new ArgumentOutOfRangeException(nameof(vm.Amount)); } Xaction transaction = new Xaction(vm.Id, vm.HouseId, vm.Description, vm.Amount); _repo.Create(transaction); _emailSender.SendEmail("*****@*****.**", "New transaction created", "general message"); _logger.Log(LogLevel.Information, "test log message"); return(true); }
public void Create_ShouldLogMessage() { //arrange XactionViewModel xact = new XactionViewModel(); _dbAdaptorMock.Setup(x => x.Create(It.IsAny <Xaction>())); //act var result = Service.Create(xact); //assert // Verify mock doesnt work with extension methods : // _loggerMock.Verify(x => x.Log(It.IsAny< LogLevel>() , It.IsAny<string>()), Times.Once); var x = _loggerMock.Invocations[0].Arguments[2] as IReadOnlyList <KeyValuePair <string, object> >; Assert.IsTrue(_loggerMock.Invocations.Any(x => ((string)(x.Arguments[2] as IReadOnlyList <KeyValuePair <string, object> >)[0].Value).Contains("test log message"))); }
public void Update__VerifyCallsToRepository() { //arrange //Xaction xact = new Xaction(transId, 2, "Test Transaction2", 1200); // xactList.Add(new Xaction(2, "Test Transaction2", 1200)); var vm = new XactionViewModel { Id = 1, HouseId = 111, Description = "A", Amount = 1000 }; //act var result = Service.Update(vm); //Assert Assert.IsTrue(result); _dbAdaptorMock.Verify(x => x.Update(It.IsAny <Xaction>()), Times.Once); // Assert.IsTrue(result); }
//public async Task<Xaction> ReadXaction(int id) //{ // return await Task.FromResult(new Xaction(1, "descr 123", 52)); //} public bool Update(XactionViewModel vm) { if (!Validate(vm)) { return(false); } Xaction transaction = new Xaction(vm.Id, vm.HouseId, vm.Description, vm.Amount); if (transaction.MaximumAmount()) { return(false); } _repo.Update(transaction); _repo.Save(); return(true); }
private bool Validate(XactionViewModel vm) { return((vm.Id == 0 || vm.HouseId == 0) ? false : true); }