Esempio n. 1
0
        public async Task Validator_ShouldPass_GoodData()
        {
            var entity = new Classification()
            {
                Id   = Guid.NewGuid(),
                Code = Guid.NewGuid().ToString(),
            };

            // setup data
            using (var db = _dbHelper.GetDbContext())
            {
                db.Classifications.RemoveRange(db.Classifications);
                await db.Classifications.AddAsync(entity);

                await db.SaveChangesAsync();
            }

            // run operation
            using (var db = _dbHelper.GetDbContext())
            {
                var validator = new UpdateClassificationCommandValidator(db);

                var command = new UpdateClassificationCommand()
                {
                    Id   = entity.Id,
                    Code = entity.Code + "Updated"
                };

                // check result
                var result = await validator.ValidateAsync(command);

                result.IsValid.ShouldBeTrue();
            }
        }
Esempio n. 2
0
        public async Task Validator_ShouldFail_CodeEmpty()
        {
            var entity = new Classification()
            {
                Id   = Guid.NewGuid(),
                Code = Guid.NewGuid().ToString(),
            };

            // setup data
            using (var db = _dbHelper.GetDbContext())
            {
                db.Classifications.RemoveRange(db.Classifications);
                await db.Classifications.AddAsync(entity);

                await db.SaveChangesAsync();
            }

            // run operation
            using (var db = _dbHelper.GetDbContext())
            {
                var validator = new UpdateClassificationCommandValidator(db);;

                var command = new UpdateClassificationCommand()
                {
                    Id   = entity.Id,
                    Code = ""
                };
                var result = await validator.ValidateAsync(command);

                // check result
                result.IsValid.ShouldBeFalse();
                result.Errors.Count.ShouldEqual(1);
                result.Errors.First().PropertyName.ShouldEqual(nameof(command.Code));
            }
        }
Esempio n. 3
0
        public async Task Validator_ShouldFail_NoIdFound()
        {
            // run operation
            using (var db = _dbHelper.GetDbContext())
            {
                var validator = new UpdateClassificationCommandValidator(db);;

                var command = new UpdateClassificationCommand()
                {
                    Id   = Guid.NewGuid(),
                    Code = Guid.NewGuid() + ""
                };
                var result = await validator.ValidateAsync(command);

                // check result
                result.IsValid.ShouldBeFalse();
                result.Errors.Count.ShouldEqual(1);
                result.Errors.First().PropertyName.ShouldEqual(nameof(command.Id));
            }
        }