コード例 #1
0
        public async Task ValidateHandler_ThrowsIfNameIsMissing()
        {
            using (var context = new TestContext())
            {
                var hamster = new HamsterCreate {
                    Color = ColorType.Gray
                };

                await Assert.ThrowsAsync <ArgumentException>(async() => await context.ValidationHandler.ValidateRulesFor(hamster));
            }
        }
コード例 #2
0
        public async Task ValidateHandler_ThrowsIfColorIsInvalid()
        {
            using (var context = new TestContext())
            {
                var hamster = new HamsterCreate {
                    Color = ColorType.Blue, Name = "Jessup O'McShanahan"
                };

                await Assert.ThrowsAsync <InvalidHamsterColorException>(async() => await context.ValidationHandler.ValidateRulesFor(hamster));
            }
        }
コード例 #3
0
        public async Task ValidateHandler_ThrowsIfNameIsTaken()
        {
            using (var context = new TestContext())
            {
                var name = "Elliot Cornfelder";

                await context.DbContext.Hamsters.AddAsync(new Hamster { Color = ColorType.Gray, Name = name });

                await context.DbContext.SaveChangesAsync();

                var hamster = new HamsterCreate {
                    Color = ColorType.Gray, Name = name
                };

                await Assert.ThrowsAsync <DuplicateHamsterException>(async() => await context.ValidationHandler.ValidateRulesFor(hamster));
            }
        }