public void ShouldUpdateParticipantLibraryItem()
        {
            var saveCommand = new SaveParticipantLibraryItemCommand()
            {
                NexusKey    = pliItem1.NexusKey,
                Name        = PL_ITEM_1_NAME_UPDATED,
                DisplayCode = PL_ITEM_1_DISPLAY_CODE_UPDATED,
                TypeKey     = pliType2.NexusKey,
            };

            _piLibrary.Execute(saveCommand);

            //Assert
            var query = new GetParticipantLibraryItemByKeyQuery()
            {
                Key = pliItem1.NexusKey
            };

            _piLibrary.Execute(query);
            var result = query.Result;

            result.NexusKey.ShouldBe(pliItem1.NexusKey);
            result.Name.ShouldBe(PL_ITEM_1_NAME_UPDATED);
            result.DisplayCode.ShouldBe(PL_ITEM_1_DISPLAY_CODE_UPDATED);
            result.Iso2Code.ShouldBe(pliItem1.Iso2Code);
            result.TypeKey.ShouldBe(pliType2.NexusKey);
            result.TypeName.ShouldBe(pliType2.Name);
        }
Exemple #2
0
        private void SaveParticipantLibraryItem(SaveParticipantLibraryItemCommand saveParticipantLibraryItemCommand)
        {
            //AssignVersionKeyIfNotSet(saveParticipantLibraryItemCommand);
            Validate(saveParticipantLibraryItemCommand);

            var dbOperationType = _libraryWriter.Save(new ParticipantLibraryItemDto()
            {
                NexusKey    = saveParticipantLibraryItemCommand.NexusKey,
                DisplayCode = saveParticipantLibraryItemCommand.DisplayCode,
                Iso2Code    = saveParticipantLibraryItemCommand.Iso2Code,
                Iso3Code    = saveParticipantLibraryItemCommand.Iso3Code,
                Name        = saveParticipantLibraryItemCommand.Name,
                DisplayName = saveParticipantLibraryItemCommand.DisplayName,
                TypeKey     = saveParticipantLibraryItemCommand.TypeKey,
            });

            switch (dbOperationType)
            {
            case DbOperationType.Create:
                PublishItemCreatedEvent(saveParticipantLibraryItemCommand);
                break;

            case DbOperationType.Update:
                PublishItemUpdatedEvent(saveParticipantLibraryItemCommand);
                break;
            }
        }
Exemple #3
0
        //private void AssignVersionKeyIfNotSet(SaveParticipantLibraryItemCommand command)
        //{
        //    if (command.VersionKey == Guid.Empty)
        //    {
        //        command.VersionKey = Guid.NewGuid();
        //    }
        //}

        private void Validate(SaveParticipantLibraryItemCommand saveParticipantLibraryItemCommand)
        {
            var errors = new List <string>();

            //if(string.IsNullOrEmpty(saveCatalogEntryCommand.Name))
            //{
            //    errors.Add("You must specify a Name");
            //}
            //if (string.IsNullOrEmpty(saveCatalogEntryCommand.ReferenceNumber))
            //{
            //    errors.Add("You must specify a Reference Number");
            //}
            //if (string.IsNullOrEmpty(saveCatalogEntryCommand.SourceSystem))
            //{
            //    errors.Add("You must specify a Source System");
            //}
            //if (saveCatalogEntryCommand.Key == Guid.Empty)
            //{
            //    errors.Add("You must specify a Key");
            //}
            //if (saveCatalogEntryCommand.VersionNumber <= 0)
            //{
            //    errors.Add("You must specify a VersionNumber");
            //}
            //if (saveCatalogEntryCommand.MetaDataItems.Count(md => md.DataType == MetaDataItemDataType.EndorsementCategory) > 1)
            //{
            //    errors.Add("An endorsement cannot have more than one EndorsementCategory as part of its MetaData.");
            //}
            //if (errors.Any())
            //{
            //    throw new CatalogLibraryValidationException(errors.ToCommaDelimitedString());
            //}
        }
Exemple #4
0
 private void PublishItemUpdatedEvent(SaveParticipantLibraryItemCommand saveParticipantLibraryItemCommand)
 {
     _publishEndpoint.Publish <IParticipantLibraryItemUpdated>(new ParticipantLibraryItemUpdated
     {
         NexusKey    = saveParticipantLibraryItemCommand.NexusKey,
         DisplayCode = saveParticipantLibraryItemCommand.DisplayCode,
         Iso2Code    = saveParticipantLibraryItemCommand.Iso2Code,
         Iso3Code    = saveParticipantLibraryItemCommand.Iso3Code,
         Name        = saveParticipantLibraryItemCommand.Name,
         DisplayName = saveParticipantLibraryItemCommand.DisplayName,
         TypeKey     = saveParticipantLibraryItemCommand.TypeKey,
     });
 }
        public void Setup()
        {
            base.SetupDb();

            SetupParticipantLibraryTypes();
            SetupParticipantLibraryItems();

            saveCommand = new SaveParticipantLibraryItemCommand()
            {
                NexusKey    = Guid.NewGuid(),
                Name        = "newName",
                DisplayCode = "newDisplayCode",
                DisplayName = "newDisplayName",
                TypeKey     = Guid.NewGuid(),
                Iso2Code    = "NewIso2Code",
                Iso3Code    = "NewIso3Code"
            };
        }
Exemple #6
0
        public async Task ShouldCreateParticipantLibraryItemAndPublishMessage()
        {
            var randomGuid = Guid.NewGuid();

            var saveCommand = new SaveParticipantLibraryItemCommand()
            {
                NexusKey    = randomGuid,
                Name        = PL_ITEM_1_NAME + randomGuid.ToString(),
                DisplayName = randomGuid.ToString(),
                DisplayCode = PL_ITEM_1_DISPLAY_CODE + randomGuid.ToString(),
                Iso2Code    = randomGuid.ToString(),
                Iso3Code    = randomGuid.ToString(),
                TypeKey     = pliType1.NexusKey,
            };

            _piLibrary.Execute(saveCommand);
            await _createdPublishedMessageReceived;

            //Assert published message
            var publishedMessage = _createdPublishedMessageReceived.Result.Message;

            publishedMessage.ShouldBeAssignableTo <IParticipantLibraryItemCreated>();
            publishedMessage.NexusKey.ShouldBe(randomGuid);
            publishedMessage.Name.ShouldBe(PL_ITEM_1_NAME + randomGuid.ToString());
            publishedMessage.DisplayCode.ShouldBe(PL_ITEM_1_DISPLAY_CODE + randomGuid.ToString());
            publishedMessage.Iso2Code.ShouldBe(randomGuid.ToString());
            publishedMessage.TypeKey.ShouldBe(pliType1.NexusKey);
            publishedMessage.SentDate.ShouldBeInRange(DateTime.UtcNow.AddMinutes(-1), DateTime.UtcNow);

            //Assert
            var getItemQuery = new GetParticipantLibraryItemByKeyQuery(randomGuid);

            _piLibrary.Execute(getItemQuery);
            var result = getItemQuery.Result;

            result.NexusKey.ShouldBe(randomGuid);
            result.Name.ShouldBe(PL_ITEM_1_NAME + randomGuid.ToString());
            result.DisplayCode.ShouldBe(PL_ITEM_1_DISPLAY_CODE + randomGuid.ToString());
            result.Iso2Code.ShouldBe(randomGuid.ToString());
            result.TypeKey.ShouldBe(pliType1.NexusKey);
            result.TypeName.ShouldBe(pliType1.Name);
        }
        public void ShouldPublishItemUpdatedEventWhenUpdatingItem()
        {
            var saveCommand = new SaveParticipantLibraryItemCommand()
            {
                NexusKey    = pliItem1.NexusKey,
                Name        = PL_ITEM_1_NAME_UPDATED,
                DisplayCode = PL_ITEM_1_DISPLAY_CODE_UPDATED,
                TypeKey     = pliType2.NexusKey,
            };

            _piLibrary.Execute(saveCommand);

            A.CallTo(() => _publishEndpoint.Publish(A <IParticipantLibraryItemUpdated> .That.Matches(
                                                        x => x.NexusKey == saveCommand.NexusKey &&
                                                        x.DisplayCode == saveCommand.DisplayCode &&
                                                        x.DisplayName == saveCommand.DisplayName &&
                                                        x.Iso2Code == saveCommand.Iso2Code &&
                                                        x.Iso3Code == saveCommand.Iso3Code &&
                                                        x.Name == saveCommand.Name &&
                                                        x.TypeKey == saveCommand.TypeKey), default(CancellationToken)))
            .MustHaveHappened();
        }
Exemple #8
0
        public void ShouldUpdateParticipantLibraryItem()
        {
            string randomGuidString = Guid.NewGuid().ToString();

            var getAllQuery = new GetAllParticipantLibraryItemsQuery();

            _piLibrary.Execute(getAllQuery);

            var plItemToUpdate = getAllQuery.Result.FirstOrDefault();

            if (plItemToUpdate != null)
            {
                var saveCommand = new SaveParticipantLibraryItemCommand()
                {
                    NexusKey    = plItemToUpdate.NexusKey,
                    Name        = PL_ITEM_1_NAME_UPDATED + randomGuidString,
                    DisplayName = plItemToUpdate.DisplayName,
                    DisplayCode = PL_ITEM_1_DISPLAY_CODE_UPDATED + randomGuidString,
                    Iso2Code    = plItemToUpdate.Iso2Code,
                    Iso3Code    = plItemToUpdate.Iso3Code,
                    TypeKey     = plItemToUpdate.TypeKey,
                };

                _piLibrary.Execute(saveCommand);

                //Assert
                var getItemQuery = new GetParticipantLibraryItemByKeyQuery(plItemToUpdate.NexusKey);
                _piLibrary.Execute(getItemQuery);
                var result = getItemQuery.Result;

                result.NexusKey.ShouldBe(plItemToUpdate.NexusKey);
                result.Name.ShouldBe(PL_ITEM_1_NAME_UPDATED + randomGuidString);
                result.DisplayCode.ShouldBe(PL_ITEM_1_DISPLAY_CODE_UPDATED + randomGuidString);
                result.Iso2Code.ShouldBe(plItemToUpdate.Iso2Code);
                result.TypeKey.ShouldBe(plItemToUpdate.TypeKey);
                result.TypeName.ShouldBe(plItemToUpdate.TypeName);
            }
        }
Exemple #9
0
        public async Task ShouldPublishItemUpdatedEventWhenUpdatingItem()
        {
            string randomGuidString = Guid.NewGuid().ToString();

            var getAllQuery = new GetAllParticipantLibraryItemsQuery();

            _piLibrary.Execute(getAllQuery);

            var plItemToUpdate = getAllQuery.Result.FirstOrDefault();

            if (plItemToUpdate != null)
            {
                var saveCommand = new SaveParticipantLibraryItemCommand()
                {
                    NexusKey    = plItemToUpdate.NexusKey,
                    Name        = PL_ITEM_1_NAME_UPDATED + randomGuidString,
                    DisplayName = plItemToUpdate.DisplayName,
                    DisplayCode = PL_ITEM_1_DISPLAY_CODE_UPDATED + randomGuidString,
                    Iso2Code    = plItemToUpdate.Iso2Code,
                    Iso3Code    = plItemToUpdate.Iso3Code,
                    TypeKey     = plItemToUpdate.TypeKey,
                };

                _piLibrary.Execute(saveCommand);
                await _updatedPublishedMessageReceived;

                //Assert
                var publishedMessage = _updatedPublishedMessageReceived.Result.Message;
                publishedMessage.ShouldBeAssignableTo <IParticipantLibraryItemUpdated>();
                publishedMessage.NexusKey.ShouldBe(plItemToUpdate.NexusKey);
                publishedMessage.Name.ShouldBe(PL_ITEM_1_NAME_UPDATED + randomGuidString);
                publishedMessage.DisplayCode.ShouldBe(PL_ITEM_1_DISPLAY_CODE_UPDATED + randomGuidString);
                publishedMessage.Iso2Code.ShouldBe(plItemToUpdate.Iso2Code);
                publishedMessage.TypeKey.ShouldBe(plItemToUpdate.TypeKey);
                publishedMessage.SentDate.ShouldBeInRange(DateTime.UtcNow.AddMinutes(-1), DateTime.UtcNow);
            }
        }
 public IHttpActionResult Post(SaveParticipantLibraryItemCommand command)
 {
     library.Execute(command);
     return(Ok());
 }