Exemplo n.º 1
0
        public async Task CreateRoleHandler_BusinessValidationFails_BusinessRuleIsBroken()
        {
            //Setup
            var repository = new Mock <IRolesRepository>();

            repository.Setup(o => o.Find(It.IsAny <Expression <Func <Role, bool> > >())).ReturnsAsync(new List <Role>
            {
                new Role
                {
                    ApplicationId = Guid.Empty,
                    RoleName      = "TestRole",
                    RoleId        = Guid.Empty
                }
            }.AsQueryable());

            var handler = new CreateRoleBusinessRuleValidationHandler(repository.Object);

            //Act
            var result = await handler.Validate(new CreateRoleCommand(new CreateRoleDto {
                ApplicationId = Guid.Empty, RoleName = "TestRole"
            }));

            //Assert
            Assert.True(result.IsBroken());
        }
Exemplo n.º 2
0
        public async Task CreateRoleHandler_BusinessValidationPasses_DoesNotThrowException()
        {
            //Setup
            var repository = new Mock <IRolesRepository>();

            repository.Setup(o => o.Find(It.IsAny <Expression <Func <Role, bool> > >())).ReturnsAsync(new List <Role>().AsQueryable());

            var handler = new CreateRoleBusinessRuleValidationHandler(repository.Object);

            //Act
            var result = await Record.ExceptionAsync(async() => await handler.Validate(new CreateRoleCommand(new CreateRoleDto {
                ApplicationId = Guid.Empty, RoleName = "TestRole"
            })));

            //Assert
            Assert.Null(result);
        }