public async Task When_Create_Duplicate_Devise_Code_throws_Exception() { //Arr context.Devises.Add(new Devise() { Id = 1, Code = "USD", Name = "US dollar" }); await context.SaveChangesAsync(); var validator = new CreateDeviseCommandValidator(context); CreateDeviseCommand command = new CreateDeviseCommand() { Code = "USD", Name = "test", }; //act var result = validator.Validate(command, options => options.IncludeRuleSets("CreateDevise")); //Ass result.Errors[0].ErrorMessage.Should().Be("The specified Code already exists."); result.IsValid.Should().BeFalse(); }
public void When_Future_Date_Depense_Constructor_throws_ExceptionExeption() { //Arr var devise = new Devise() { Id = 1, Code = "AZE", Name = "AZEERteryty" }; var user = new User() { Id = 1, FirstName = "aa", LastName = "bb", DeviseId = 1 }; var depense = new Depense() { Id = 1, DeviseId = 1, UserId = 1, Montant = 10, Date = DateTime.Now.AddDays(-1) }; context.Depenses.Add(depense); context.Devises.Add(devise); context.Users.Add(user); context.SaveChangesAsync(); var validator = new UpdateDepenseCommandValidator(context); UpdateDepenseCommand command = new UpdateDepenseCommand() { Id = 1, UserId = 1, Date = DateTime.Now.AddDays(2), NatureDepense = "Hotel", Montant = 10, DeviseId = 1, Commentaire = "Commentaire" }; //Act var result = validator.Validate(command, options => options.IncludeRuleSets("UpdateDepense")); //Ass result.Errors[0].ErrorMessage.Should().Be("Une dépense ne peut pas avoir une date dans le futur."); result.IsValid.Should().BeFalse(); }