public void When_Comment_IsNullOrEmpty_Date_Depense_Constructor_throws_ExceptionExeption(string commentaire) { //Arr var devise = new Devise() { Id = 1, Code = "AZE", Name = "AZEERteryty" }; var user = new User() { Id = 1, FirstName = "aa", LastName = "bb", DeviseId = 1 }; context.Devises.Add(devise); context.Users.Add(user); var validator = new CreateDepenseCommandValidator(context); CreateDepenseCommand command = new CreateDepenseCommand() { UserId = 1, Date = DateTime.Now, NatureDepense = "Hotel", Montant = 10, DeviseId = 1, Commentaire = commentaire }; //Act var result = validator.Validate(command, options => options.IncludeRuleSets("CreateDepense")); //Ass result.Errors[0].ErrorMessage.Should().Be("Le commentaire est obligatoire."); }
public async Task When_Valid_Properties__Return_Valid_Depense() { var date = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); 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 = date }; context.Devises.Add(devise); context.Users.Add(user); context.Depenses.Add(depense); await context.SaveChangesAsync(); var validator = new CreateDepenseCommandValidator(context); //Arr CreateDepenseCommand command = new CreateDepenseCommand() { UserId = 1, Date = DateTime.Now, NatureDepense = "Hotel", Montant = 15, DeviseId = 1, Commentaire = "commentaire" }; //Act var result = validator.Validate(command, options => options.IncludeRuleSets("CreateDepense")); //Assert result.IsValid.Should().BeTrue(); }
public async Task When_User_Create_Depense_Same_Date_Same_Montant_throws_ExceptionExeption() { //Arr var date = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); 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 = date }; context.Devises.Add(devise); context.Users.Add(user); context.Depenses.Add(depense); await context.SaveChangesAsync(); var validator = new CreateDepenseCommandValidator(context); CreateDepenseCommand command = new CreateDepenseCommand() { UserId = 1, Date = date, NatureDepense = "Hotel", Montant = 10, DeviseId = 1, Commentaire = "Commentaire" }; //Act var result = validator.Validate(command, options => options.IncludeRuleSets("CreateDepense")); //Ass result.Errors[0].ErrorMessage.Should().Be("Un utilisateur ne peut pas déclarer deux fois la même dépense (même date et même montant)."); }
public void When_User_Devise_And_Depense_Devise_Are_Different_throws_ExceptionExeption() { //Arr var devise = new Devise() { Id = 1, Code = "AZE", Name = "AZEERteryty" }; var devise2 = new Devise() { Id = 2, Code = "AAZ", Name = "AAEERteryty" }; var user = new User() { Id = 1, FirstName = "aa", LastName = "bb", DeviseId = 1 }; context.Devises.AddRange(devise, devise2); context.Users.Add(user); var validator = new CreateDepenseCommandValidator(context); CreateDepenseCommand command = new CreateDepenseCommand() { UserId = 1, Date = DateTime.Now, NatureDepense = "Hotel", Montant = 10, DeviseId = 2, Commentaire = "Commentaire" }; //Act var result = validator.Validate(command, options => options.IncludeRuleSets("CreateDepense")); //Ass result.Errors[0].ErrorMessage.Should().Be("La devise de la dépense doit être identique à celle de l'utilisateur."); result.IsValid.Should().BeFalse(); }
public void When_More_Then_3_Months_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 }; context.Devises.Add(devise); context.Users.Add(user); var validator = new CreateDepenseCommandValidator(context); CreateDepenseCommand command = new CreateDepenseCommand() { UserId = 1, Date = DateTime.Now.AddMonths(-4), NatureDepense = "Hotel", Montant = 10, DeviseId = 1, Commentaire = "Commentaire" }; //Act var result = validator.Validate(command, options => options.IncludeRuleSets("CreateDepense")); //Ass result.Errors[0].ErrorMessage.Should().Be("Une dépense ne peut pas être datée de plus de 3 mois."); result.IsValid.Should().BeFalse(); }