public void WhenISaveTheNewOrganization(string raisonSociale) { var expectedCommand = new AddOrganizationCommand() { Id = Guid.NewGuid(), RaisonSociale = _expectedOrganization.RaisonSociale, Reference = _expectedOrganization.Reference, FormeJuridique = _expectedOrganization.FormeJuridique, Effectif = _expectedOrganization.Effectif.Value }; var browser = new Browser(with => { var commandProcessor = new Mock <IAmACommandProcessor>(); var createCommandFactory = new Mock <ICommandFactory <AddOrganizationCommand> >(); var modifyCommandFactory = new Mock <ICommandFactory <ChangeOrganizationCommand> >(); createCommandFactory.Setup(o => o.CreateCommand(It.IsAny <INancyModule>())).Returns(expectedCommand); commandProcessor.Setup(o => o.Send(expectedCommand)); with.Module(new OrganizationCommandModule(commandProcessor.Object, createCommandFactory.Object, modifyCommandFactory.Object)); with.ViewFactory <TestViewFactory>(); }); var serializedCommand = JsonConvert.SerializeObject(expectedCommand); var response = browser.Post("/Organization", (with) => { with.Header("content-type", "application/json"); with.Body(serializedCommand); }); Assert.Equal(HttpStatusCode.Created, response.StatusCode); }
public void HttpNotFoundWhenCallingWrongEndpoint() { InitializeLogger(); var commandProcessor = new Mock <IAmACommandProcessor>(); var CreateCommandFactory = new Mock <ICommandFactory <AddOrganizationCommand> >(); var ModifyCommandFactory = new Mock <ICommandFactory <ChangeOrganizationCommand> >(); var returnedCommand = new AddOrganizationCommand() { CodeNAF = "456546", FormeJuridique = "Toto", Id = Guid.NewGuid() }; var serializedCommand = JsonConvert.SerializeObject(returnedCommand); CreateCommandFactory.Setup(o => o.CreateCommand(It.IsAny <INancyModule>())).Returns(returnedCommand); commandProcessor.Setup(o => o.Send(returnedCommand)); var browser = new Browser(with => { with.Module(new OrganizationCommandModule(commandProcessor.Object, CreateCommandFactory.Object, ModifyCommandFactory.Object)); with.ViewFactory <TestViewFactory>(); }); var response = browser.Post("/toto", (with) => { with.Header("content-type", "application/json"); with.Body(serializedCommand); }); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); }
public void Validate_WhenValidCommandIsCreatedFromScratch_ValidationReturnsAValidCommad (int organizationId, string formeJuridique, string reference, string siret, string codeNAF , string identifiantConventionCollective, int effectif, string raisonSociale) { var addPMCommand = new AddOrganizationCommand() { OrganizationId = organizationId, FormeJuridique = formeJuridique, Reference = reference, SIRET = siret, CodeNAF = codeNAF, IdentifiantConventionCollective = identifiantConventionCollective, Effectif = 42, RaisonSociale = raisonSociale }; var validation = (addPMCommand as ICanBeValidated <AddOrganizationCommand>).Validate(); addPMCommand.CodeNAF.Should().Be(codeNAF); addPMCommand.OrganizationId.Should().Be(organizationId); addPMCommand.FormeJuridique.Should().Be(formeJuridique); addPMCommand.Reference.Should().Be(reference); addPMCommand.SIRET.Should().Be(siret); addPMCommand.IdentifiantConventionCollective.Should().Be(identifiantConventionCollective); addPMCommand.Effectif.Should().Be(effectif); addPMCommand.RaisonSociale.Should().Be(raisonSociale); validation.IsLeft.Should().Be(false); validation.IsRight.Should().Be(true); }
public async Task <Guid> HandleCommand(AddOrganizationCommand cmd) { //lookup the StateProvince var state = _stateProvinceRepository.Get(cmd.StateProvinceId); if (state == null) { throw new FormatException("Submitted State/Province is invalid."); } //lookup the OrgType var orgType = _orgTypeRepository.Get(cmd.OrgTypeId); if (orgType == null) { throw new FormatException("Invalid Organization type submitted."); } //set the address var address = new Address(cmd.Address1, cmd.Address2, cmd.City, state, cmd.PostalCode, cmd.AddressType); var org = new Organization(cmd.Name, cmd.DbaName, cmd.EIN, address, orgType, cmd.ParentId, cmd.Active, cmd.Verified); _organizationRepository.Add(org); _organizationRepository.Save(); //fire event here await FireOrgAddedEvent(org, cmd); return(org.ID); }
public override Organization CreateOrganizationDomainObject(AddOrganizationCommand addOrganizationCommand) { Organization pm = base.CreateOrganizationDomainObject(addOrganizationCommand); pm.Extension = new OrganizationAxa() { OrganizationId = addOrganizationCommand.OrganizationId, NumAbonne = ((AxaAddOrganizationCommandExtension)addOrganizationCommand.Extension).NumAbonne }; return(pm); }
public async Task <IActionResult> CreateOrg([FromBody] AddOrganizationCommand cmd) { try { var newOrgId = await _addOrganizationCommandHandler.HandleCommand(cmd); return(Ok(new NewOrgResultDto { OrganizationID = (Guid)newOrgId })); } catch (Exception ex) { if (ex is FormatException || ex is UnverifiedOrganizationException) { return(BadRequest(ex.Message)); } //TODO: log what happened here... return(BadRequest("There was an error.")); } }
private async Task <bool> FireOrgAddedEvent(Organization org, AddOrganizationCommand cmd) { var addressDtos = new List <AddressDto>(); addressDtos.AddRange(org.Addresses.Select(x => new AddressDto { Address1 = x.Address1, Address2 = x.Address2, City = x.City, ID = x.ID, PostalCode = x.PostalCode, StateProvince = x.AddressStateProvince.Name, TypeOfAddress = x.TypeOfAddress })); await _messageProducer.ProduceEventAsync <OrganizationCreatedEvent>(new OrganizationCreatedEvent { CorrelationId = (cmd.CommandId == null) ? Guid.NewGuid() : (Guid)cmd.CommandId, EntityId = org.ID, Active = org.Active, Addresses = addressDtos, DbaName = org.DbaName, EIN = org.EIN, Name = org.Name, OrgType = new OrgTypeDto { CanSell = org.OrgType.CanSell, Description = org.OrgType.Description, ID = org.OrgType.ID, Name = org.OrgType.Name }, ParentId = org.ParentId, TimeStamp = org.Created, Verified = org.Verified }); return(true); }
public virtual Organization CreateOrganizationDomainObject(AddOrganizationCommand addOrganizationCommand) { return(new Organization(addOrganizationCommand.OrganizationId, addOrganizationCommand.Reference, addOrganizationCommand.RaisonSociale, addOrganizationCommand.FormeJuridique, addOrganizationCommand.Effectif, addOrganizationCommand.SIRET, addOrganizationCommand.CodeNAF, addOrganizationCommand.IdentifiantConventionCollective)); }
public void Validate_WhenAddOrganizationCommandIsUnvalid_ThenReturnedObjectIsList(AddOrganizationCommand command) { var Validation = (command as ICanBeValidated <AddOrganizationCommand>).Validate(); Validation.IsLeft.Should().Be(true); Validation.IsRight.Should().Be(false); //var Errors = Validation.Match(Right: x=>new Unit(), Left:(a)=> return a); }
public void Validate_WhenAddOrganizationCommandIsValid_ThenReturnedObjectIsAddOrganizationCommand(AddOrganizationCommand command) { var Validation = (command as ICanBeValidated <AddOrganizationCommand>).Validate(); Validation.IsLeft.Should().Be(false); Validation.IsRight.Should().Be(true); }