コード例 #1
0
        public ProjectValidator()
        {
            RuleFor(project => project.Id).SetValidator(new EntityIdValidator());
            RuleFor(project => project.Name).SetValidator(new ProjectNameValidator());
            RuleFor(project => project.StartDate).SetValidator(new DateAndTimeValidator());
            RuleFor(project => project.ClientId).SetValidator(new EntityIdValidator());

            RuleFor(project => project.Code).SetValidator(new ProjectCodeValidator())
            .DependentRules(() =>
            {
                RuleFor(current => current.Code).Custom((code, context) =>
                {
                    if (context.ParentContext.RootContextData.ContainsKey("project"))
                    {
                        var changedProject = context.ParentContext.RootContextData["project"] as Project;

                        if (code.Equals(changedProject?.Code))
                        {
                            context.AddFailure("O código do novo projeto não pode ser igual ao atual.");
                        }
                    }
                });
            });

            RuleFor(project => project.Budget).SetValidator(new MoneyValidator());
            RuleFor(project => project.Status).SetValidator(new ProjectStatusValidator())
            .When(status => !status.Equals(ProjectStatus.Default()));

            RuleFor(project => project.Owner).SetValidator(new EmailValidator())
            .When(project => !project.Owner.Equals(Email.Empty()));

            RuleFor(project => project.OrderNumber).SetValidator(new ServiceOrderNumberValidator())
            .When(order => !order.OrderNumber.Equals(ServiceOrderNumber.Empty()));
        }
コード例 #2
0
        public IntegrationProjectDataset(AppFabricDbContext db)
        {
            DbContext = db;

            DatabaseFixture = new Fixture();

            DatabaseFixture.Register <ProjectState>(() =>
                                                    new ProjectState(DatabaseFixture.Create <Guid>(),
                                                                     DatabaseFixture.Create <string>(),
                                                                     DatabaseFixture.Create <string>(),
                                                                     DatabaseFixture.Create <decimal>(),
                                                                     DatabaseFixture.Create <DateTime>(),
                                                                     DatabaseFixture.Create <Guid>(),
                                                                     string.Format($"{DatabaseFixture.Create<string>()}@teste.com"),
                                                                     DatabaseFixture.Create <string>(),
                                                                     ProjectStatus.Default().Value,
                                                                     BitConverter.GetBytes(DatabaseFixture.Create <int>())));

            DatabaseFixture.Register <ProjectProjection>(() =>
                                                         new ProjectProjection(DatabaseFixture.Create <Guid>(),
                                                                               DatabaseFixture.Create <string>(),
                                                                               DatabaseFixture.Create <string>(),
                                                                               DatabaseFixture.Create <decimal>(),
                                                                               DatabaseFixture.Create <DateTime>(),
                                                                               DatabaseFixture.Create <Guid>(),
                                                                               DatabaseFixture.Create <string>(),
                                                                               string.Format($"{DatabaseFixture.Create<string>()}@teste.com"),
                                                                               DatabaseFixture.Create <string>(),
                                                                               DatabaseFixture.Create <int>(),
                                                                               DatabaseFixture.Create <string>(),
                                                                               DatabaseFixture.Create <int>()));
        }
コード例 #3
0
 private ProjectAddedEvent(EntityId id, ProjectName name, ProjectCode code, DateAndTime startDate, Money budget, EntityId clientId, Version version)
     : base(DateTime.Now, version)
 {
     Id          = id;
     Code        = code;
     Name        = name;
     Budget      = budget;
     StartDate   = startDate;
     ClientId    = clientId;
     Owner       = Email.Empty();
     Status      = ProjectStatus.Default();
     OrderNumber = ServiceOrderNumber.Empty();
 }
コード例 #4
0
        public void project_add_command_succed()
        {
            var fixture = new Fixture().Customize(new AutoNSubstituteCustomization {
                ConfigureMembers = true
            });

            fixture.Register <EntityId>(() => EntityId.From(fixture.Create <Guid>()));
            fixture.Register <ProjectName>(() => ProjectName.From(fixture.Create <string>()));
            fixture.Register <ProjectCode>(() => ProjectCode.From(fixture.Create <string>()));
            fixture.Register <DateAndTime>(() => DateAndTime.From(fixture.Create <DateTime>()));
            fixture.Register <ProjectStatus>(() => ProjectStatus.Default());
            fixture.Register <ServiceOrderNumber>(() => ServiceOrderNumber.Empty());
            fixture.Register <Email>(() => Email.From(string.Format($"{fixture.Create<string>()}@teste.com")));
            fixture.Register <Project>(() => Project.NewRequest(fixture.Create <EntityId>(),
                                                                fixture.Create <ProjectName>(), fixture.Create <ProjectCode>(),
                                                                fixture.Create <DateAndTime>(), fixture.Create <Money>(), fixture.Create <EntityId>()));
            fixture.Register <User>(() => User.From(fixture.Create <EntityId>(),
                                                    fixture.Create <Name>(), fixture.Create <SocialSecurityId>(),
                                                    fixture.Create <Email>(), fixture.Create <Version>()));

            var finalProject = fixture.Create <Project>();
            var finalClient  = fixture.Create <User>();

            var command = fixture.Build <AddProjectCommand>()
                          .With(project => project.Name, finalProject.Name.Value)
                          .With(project => project.Code, finalProject.Code.Value)
                          .With(project => project.Budget, finalProject.Budget.Value)
                          .With(project => project.ClientId, finalProject.ClientId.Value)
                          .With(project => project.StartDate, finalProject.StartDate.Value)
                          .Create();

            var mediator  = fixture.Create <IMediator>();
            var logger    = fixture.Create <ILogger <AddProjectCommandHandler> >();
            var projectDb = fixture.Create <IDbSession <IProjectRepository> >();
            var userDb    = fixture.Create <IDbSession <IUserRepository> >();
            var handler   = new AddProjectCommandHandler(logger, mediator, projectDb, userDb);

            var result = handler.Execute(command);

            userDb.Received().Repository.Get(finalProject.ClientId).Returns(finalClient);
            projectDb.Received().Repository.Add(finalProject);
            projectDb.Received().SaveChanges();
            mediator.Received(1).Publish(Arg.Any <ProjectAddedEvent>());

            Assert.True(result.IsSucceed);
        }