Beispiel #1
0
        public override Task <CommandResult <long> > Handle(CreateWiterCommand request)
        {
            Writer writer = new Writer(BusinessId.FromGuid(request.BusinessId), request.FirstName, request.LastName);

            _writerRepository.Insert(writer);
            _writerRepository.Commit();
            return(OkAsync(writer.Id));
        }
Beispiel #2
0
        public IActionResult Get([FromServices] IPersonCommandRepository repository, [FromQuery] Guid id)
        {
            _logger.LogInformation("Hi");
            Person person = repository.Get(BusinessId.FromGuid(id));

            return(Ok(new
            {
                FirstName = person.FirstName,
                LastName = person.LastName,
                Id = person.Id.Value
            }));
        }
Beispiel #3
0
        public void when_pass_invalid_firstName_expect_throw_invalid_lastName_exception()
        {
            //Arrange
            BusinessId       personId  = BusinessId.FromGuid(Guid.NewGuid());
            string           firstName = "ajangjoo";
            string           lastName  = "";
            HashSet <string> tags      = new HashSet <string> {
                "Tag01"
            };

            //Act
            var exception = Record.Exception(() => Person.Create(personId, firstName, lastName));

            //Assert
            exception.ShouldNotBeNull();
            exception.ShouldBeOfType <InvalidLastNameException>();
        }
    public void when_pass_valid_Input_value_expect_person_create()
    {
        string     firstName = "mahdiye";
        string     lastName  = "hosseini";
        BusinessId personId  = BusinessId.FromGuid(Guid.NewGuid());

        var person = Person.Create(personId, firstName, lastName);

        person.ShouldNotBeNull();
        person.Id.ShouldBe(personId);
        person.FirstName.ShouldBe(firstName);
        person.LastName.ShouldBe(lastName);
        person.GetEvents().Count().ShouldBe(1);
        var @event = person.GetEvents().First();

        @event.ShouldBeOfType <PersonCreated>();
    }
Beispiel #5
0
        public void when_pass_valid_Input_value_expect_person_create_and_register_to_databse()
        {
            //Arrange
            var command = new CreateNewPersonCommand
            {
                FirstName = "Alireza",
                LastName  = "Oroumand",
                Id        = Guid.NewGuid()
            };

            var commanHandler = new CreateNewPersonCommandHandler(fixture.PersonCommandRepository);

            // Act
            commanHandler.Handle(command);
            //Assert
            var person = fixture.DbContext.People.FirstOrDefault(c => c.Id == BusinessId.FromGuid(command.Id));

            person.ShouldNotBeNull();
            person.FirstName.ShouldBe(command.FirstName);
            person.LastName.ShouldBe(command.LastName);
        }
Beispiel #6
0
        public void when_pass_valid_Input_value_expect_person_create()
        {
            //Arrange
            string           firstName = "Alrieza";
            string           lastName  = "Oroumand";
            BusinessId       personId  = BusinessId.FromGuid(Guid.NewGuid());
            HashSet <string> tags      = new HashSet <string> {
                "Tag01"
            };

            //Act
            var person = Person.Create(personId, firstName, lastName);

            //Assert
            person.ShouldNotBeNull();
            person.Id.ShouldBe(personId);
            person.FirstName.ShouldBe(firstName);
            person.LastName.ShouldBe(lastName);
            person.GetEvents().Count().ShouldBe(1);
            var @event = person.GetEvents().First();

            @event.ShouldBeOfType <PersonCreated>();
        }
 public static void AddBusinessId(this ModelBuilder modelBuilder)
 {
     foreach (var entityType in modelBuilder.Model
              .GetEntityTypes()
              .Where(e => typeof(AggregateRoot).IsAssignableFrom(e.ClrType) ||
                     typeof(Entity).IsAssignableFrom(e.ClrType)))
     {
         modelBuilder.Entity(entityType.ClrType)
         .Property <BusinessId>("BusinessId").HasConversion(c => c.Value, d => BusinessId.FromGuid(d))
         .IsUnicode()
         .IsRequired();
     }
 }
Beispiel #8
0
 public void Configure(EntityTypeBuilder <Person> builder)
 {
     builder.Property(c => c.Id).HasConversion(c => c.Value, c => BusinessId.FromGuid(c));
 }
Beispiel #9
0
        public void Handle(CreateNewPersonCommand command)
        {
            var person = Person.Create(BusinessId.FromGuid(command.Id), command.FirstName, command.LastName);

            personCommandRepository.Add(person);
        }