Esempio n. 1
0
        public async Task Create_Valid_Devise()
        {
            //Arr

            context.Devises.Add(new Devise()
            {
                Id = 3, Code = "USD", Name = "US dollar"
            });

            await context.SaveChangesAsync();

            var validator = new CreateDeviseCommandValidator(context);

            CreateDeviseCommand command = new CreateDeviseCommand()
            {
                Code = "ALD",
                Name = "AL Dinar",
            };

            //Act

            var result = validator.Validate(command, options => options.IncludeRuleSets("CreateDevise"));

            //Ass

            result.IsValid.Should().BeTrue();
        }
Esempio n. 2
0
        public async Task When_Create_Duplicate_Devise_Name_throws_Exception()
        {
            //Arr

            context.Devises.Add(new Devise()
            {
                Id = 2, Code = "USD", Name = "US dollar"
            });

            await context.SaveChangesAsync();

            var validator = new CreateDeviseCommandValidator(context);

            CreateDeviseCommand command = new CreateDeviseCommand()
            {
                Code = "USA",
                Name = "US dollar",
            };

            //act

            var result = validator.Validate(command, options => options.IncludeRuleSets("CreateDevise"));

            //Ass

            result.Errors.Count.Should().Be(1);
            result.Errors[0].ErrorMessage.Should().Be("The specified Name already exists.");

            result.IsValid.Should().BeFalse();
        }
Esempio n. 3
0
        public async Task When_Create_Short_Devise_Code_throws_Exception()
        {
            //Arr

            var validator = new CreateDeviseCommandValidator(context);

            CreateDeviseCommand command = new CreateDeviseCommand()
            {
                Code = "US",
                Name = "US dollar",
            };

            //Acc

            var result = validator.Validate(command, options => options.IncludeRuleSets("CreateDevise"));

            //Ass

            result.Errors[0].ErrorMessage.Should().Be("Code must be 3 characters.");

            result.IsValid.Should().BeFalse();
        }