예제 #1
0
        public void TestCreateMappingRequestSuccess()
        {
            CreateMappingRequest createRequest = new CreateMappingRequest();

            createRequest.ICA                                     = "009674";
            createRequest.SubscriberId                            = "13147449999";
            createRequest.SubscriberType                          = "PHONE_NUMBER";
            createRequest.AccountUsage                            = "RECEIVING";
            createRequest.AccountNumber                           = "5184680430000006";
            createRequest.DefaultIndicator                        = "T";
            createRequest.ExpiryDate                              = 201401;
            createRequest.Alias                                   = "My Debit Card";
            createRequest.Address.Line1                           = "123 Main Street";
            createRequest.Address.City                            = "OFallon";
            createRequest.Address.CountrySubdivision              = "MO";
            createRequest.Address.Country                         = "USA";
            createRequest.Address.PostalCode                      = 63368;
            createRequest.CardholderFullName.CardholderFirstName  = "John";
            createRequest.CardholderFullName.CardholderMiddleName = "Q";
            createRequest.CardholderFullName.CardholderLastName   = "Public";
            createRequest.DateOfBirth                             = 19460102;
            CreateMapping createMapping = service.GetCreateMapping(createRequest);

            Assert.IsTrue(createMapping != null);
            Assert.IsTrue(createMapping.RequestId != null && createMapping.RequestId > 0);
            Assert.IsTrue(createMapping.Mapping.MappingId != null && createMapping.Mapping.MappingId > 0);
        }
        public void ValidContractAdded()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

            var service = new PartyService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);
            var identifier = new MdmId { SystemName = "Test", Identifier = "A" };
            var message = new CreateMappingRequest
            {
                EntityId = 12,
                Mapping = identifier
            };

            var system = new MDM.SourceSystem { Name = "Test" };
            var mapping = new PartyMapping { System = system, MappingValue = "A" };
            validatorFactory.Setup(x => x.IsValid(It.IsAny<CreateMappingRequest>(), It.IsAny<IList<IRule>>())).Returns(true);
            mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.MdmId, PartyMapping>(identifier)).Returns(mapping);

            var party = new MDM.Party();
            repository.Setup(x => x.FindOne<MDM.Party>(12)).Returns(party);

            // Act
            var candidate = (PartyMapping)service.CreateMapping(message);

            // Assert
            Assert.AreSame(mapping, candidate);
            repository.Verify(x => x.Save(party));
            repository.Verify(x => x.Flush());
        }
예제 #3
0
        public override bool IsValid(CreateMappingRequest request)
        {
            var mapping = request.Mapping;
            var range   = new EnergyTrading.DateRange(mapping.StartDate, mapping.EndDate);

            var entity = this.repository.FindOne <TEntity>(request.EntityId) as MDM.PartyRole;

            if (entity == null)
            {
                this.Message = string.Format(EntityNotFoundMessageTemplate, typeof(TEntity).Name, request.EntityId);
                return(false);
            }

            var count = this.repository.FindPartyRoleOverlappingMappingCount <TMapping>(
                mapping.SystemName,
                mapping.Identifier,
                range,
                entity.PartyRoleType);

            if (count > 0)
            {
                this.Message = string.Format(
                    MessageTemplate,
                    mapping.Identifier,
                    mapping.SystemName,
                    range.Start,
                    range.Finish);
                return(false);
            }

            return(true);
        }
        public void EntityNotFound()
        {
            // Arrange
            var validatorFactory = new Mock <IValidatorEngine>();
            var mappingEngine    = new Mock <IMappingEngine>();
            var repository       = new Mock <IRepository>();
            var searchCache      = new Mock <ISearchCache>();

            var service = new CurveService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var message = new CreateMappingRequest
            {
                EntityId = 12,
                Mapping  = new NexusId {
                    SystemName = "Test", Identifier = "A"
                }
            };

            validatorFactory.Setup(x => x.IsValid(It.IsAny <CreateMappingRequest>(), It.IsAny <IList <IRule> >())).Returns(true);

            // Act
            var candidate = service.CreateMapping(message);

            // Assert
            Assert.IsNull(candidate);
        }
예제 #5
0
        public IHttpActionResult Post(int id, [FromBody] Mapping mapping)
        {
            return(WebHandler(() =>
            {
                var request = new CreateMappingRequest
                {
                    EntityId = id,
                    Mapping = mapping
                };

                IEntityMapping entityMapping;

                using (var scope = new TransactionScope(TransactionScopeOption.Required, WriteOptions()))
                {
                    entityMapping = this.service.CreateMapping(request);
                    scope.Complete();
                }

                var location = String.Format("{0}/{1}",
                                             this.Request.RequestUri.AbsolutePath.Substring(1),
                                             entityMapping.Id);

                notificationService.Notify(() => GetContract(id).Contract, service.ContractVersion, Operation.Modified);

                return new StatusCodeResultWithLocation(this.Request, HttpStatusCode.Created, location);
            }));
        }
        public void NoOverlappingIndentifierShouldPass()
        {
            // Assert
            var start = new DateTime(1999, 1, 1);
            var finish = new DateTime(2020, 12, 31);
            var validity = new DateRange(start, finish);
            var system = new SourceSystem { Name = "Test" };
            var expectedPartyRole = new PartyRole() { PartyRoleType = "PartyRole" };
            var expected = new PartyRoleMapping { System = system, MappingValue = "1", Validity = validity, PartyRole = expectedPartyRole };
            var list = new List<PartyRoleMapping> { expected };
            var repository = new Mock<IRepository>();
            repository.Setup(x => x.Queryable<PartyRoleMapping>()).Returns(list.AsQueryable());
            repository.Setup(x => x.FindOne<PartyRole>(It.IsAny<int>())).Returns(expectedPartyRole);

            var identifier = new EnergyTrading.Mdm.Contracts.MdmId
            {
                SystemName = "Test",
                Identifier = "1",
                StartDate = start.AddHours(-10),
                EndDate = start.AddHours(-5)
            };

            var request = new CreateMappingRequest() { EntityId = 1, Mapping = identifier };
            var rule = new PartyRoleCreateMappingdNoOverlappingRule<PartyRole, PartyRoleMapping>(repository.Object);

            // Act
            var result = rule.IsValid(request);

            // Assert
            repository.Verify(x => x.FindOne<PartyRole>(It.IsAny<int>()));
            Assert.IsTrue(result, "Rule failed");
        }
예제 #7
0
        public CreateMapping GetCreateMapping(CreateMappingRequest request)
        {
            string response = "";
            Dictionary <string, string> responseMap = doRequest(GetURL(), "POST", Serializer <CreateMappingRequest> .Serialize(request).InnerXml);

            responseMap.TryGetValue(MESSAGE, out response);
            return(Serializer <CreateMapping> .Deserialize(response));
        }
예제 #8
0
        public async Task <Mapping> InsertSurveyMappingAsync(string email, CreateMappingRequest mappingRequest)
        {
            if (string.IsNullOrWhiteSpace(email))
            {
                throw new ArgumentNullException("Email is mandatory!!");
            }
            try
            {
                var survey = await _dbContext.Survey.SingleOrDefaultAsync(survey => survey.UserEmail == email && survey.SurveyId == mappingRequest.SurveyId);

                if (survey != null)
                {
                    var mappings = await _dbContext.GroupTextMapping
                                   .Where(mapping => mapping.Survey.SurveyId == mappingRequest.SurveyId &&
                                          mapping.TextEntry.TextId == mappingRequest.TextId)
                                   .ToListAsync();

                    foreach (var mapping in mappings)
                    {
                        mapping.IsDeleted        = true;
                        mapping.LastModifiedDate = DateTime.UtcNow;
                    }
                    var text = await _dbContext.TextEntry.SingleOrDefaultAsync(text => text.TextId == mappingRequest.TextId);

                    var group = await _dbContext.Group.SingleOrDefaultAsync(group => group.GroupId == mappingRequest.GroupId);

                    var map = new GroupTextMappingEntity()
                    {
                        TextEntry   = text,
                        Group       = group,
                        Survey      = survey,
                        IsDeleted   = false,
                        CreatedDate = DateTime.UtcNow
                    };

                    await _dbContext.GroupTextMapping.AddAsync(map);

                    await _dbContext.SaveChangesAsync();

                    return(new Mapping()
                    {
                        MappingId = map.MappingId,
                        TextId = map.TextEntry.TextId,
                        GroupId = map.Group.GroupId,
                        SurveyId = map.Survey.SurveyId
                    });
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public void OverlappingIndentifierShouldFail()
        {
            // Assert
            var start    = new DateTime(1999, 1, 1);
            var finish   = new DateTime(2020, 12, 31);
            var validity = new DateRange(start, finish);
            var system   = new SourceSystem {
                Name = "Test"
            };
            var expectedPartyRole = new PartyRole()
            {
                PartyRoleType = "PartyRole"
            };
            var expected = new PartyRoleMapping {
                System = system, MappingValue = "1", Validity = validity, PartyRole = expectedPartyRole
            };
            var list = new List <PartyRoleMapping> {
                expected
            };
            var repository = new Mock <IRepository>();

            repository.Setup(x => x.Queryable <PartyRoleMapping>()).Returns(list.AsQueryable());
            repository.Setup(x => x.FindOne <PartyRole>(It.IsAny <int>())).Returns(expectedPartyRole);

            var identifier = new EnergyTrading.Mdm.Contracts.MdmId
            {
                SystemName = "Test",
                Identifier = "1",
                StartDate  = start.AddHours(5),
                EndDate    = start.AddHours(10)
            };

            var request = new CreateMappingRequest()
            {
                EntityId = 1, Mapping = identifier
            };
            var rule = new PartyRoleCreateMappingdNoOverlappingRule <PartyRole, PartyRoleMapping>(repository.Object);

            // Act
            var result = rule.IsValid(request);

            // Assert
            repository.Verify(x => x.FindOne <PartyRole>(It.IsAny <int>()));
            Assert.IsFalse(result, "Rule failed");
        }
        public void ValidContractAdded()
        {
            // Arrange
            var validatorFactory = new Mock <IValidatorEngine>();
            var mappingEngine    = new Mock <IMappingEngine>();
            var repository       = new Mock <IRepository>();
            var searchCache      = new Mock <ISearchCache>();

            var service    = new CurveService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);
            var identifier = new NexusId {
                SystemName = "Test", Identifier = "A"
            };
            var message = new CreateMappingRequest
            {
                EntityId = 12,
                Mapping  = identifier
            };

            var system = new MDM.SourceSystem {
                Name = "Test"
            };
            var mapping = new CurveMapping {
                System = system, MappingValue = "A"
            };

            validatorFactory.Setup(x => x.IsValid(It.IsAny <CreateMappingRequest>(), It.IsAny <IList <IRule> >())).Returns(true);
            mappingEngine.Setup(x => x.Map <NexusId, CurveMapping>(identifier)).Returns(mapping);

            var curve = new MDM.Curve();

            repository.Setup(x => x.FindOne <MDM.Curve>(12)).Returns(curve);

            validatorFactory.Setup(x => x.IsValid(It.IsAny <object>(), It.IsAny <IList <IRule> >())).Returns(false);

            // Act
            var candidate = (CurveMapping)service.CreateMapping(message);

            // Assert
            Assert.AreSame(mapping, candidate);
            repository.Verify(x => x.Save(curve));
            repository.Verify(x => x.Flush());
        }
        public void EntityNotFound()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

            var service = new PartyService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var message = new CreateMappingRequest
                {
                    EntityId = 12,
                    Mapping = new MdmId { SystemName = "Test", Identifier = "A" }
                };

            validatorFactory.Setup(x => x.IsValid(It.IsAny<CreateMappingRequest>(), It.IsAny<IList<IRule>>())).Returns(true);

            // Act
            var candidate = service.CreateMapping(message);

            // Assert
            Assert.IsNull(candidate);
        }
예제 #12
0
        /// <summary>
        /// Add a mapping to an existing entity.
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public IEntityMapping CreateMapping(CreateMappingRequest message)
        {
            // Check it's ok
            this.Validate(message);

            // Get a reference to the entity we should operate against
            var entity = this.repository.FindOne <TEntity>(message.EntityId);

            if (entity == null)
            {
                return(null);
            }

            // Create the mapping and save
            var mapping = this.MappingEngine.Map <EnergyTrading.Mdm.Contracts.MdmId, TMapping>(message.Mapping);

            entity.ProcessMapping(mapping);

            this.repository.Save(entity);
            this.repository.Flush();
            searchCache.Clear();

            return(mapping);
        }
예제 #13
0
        public async Task <ActionResult <Mapping> > Post([FromRoute] string userEmail, [FromRoute] int surveyId, [FromBody] CreateMappingRequest request)
        {
            request.SurveyId = surveyId;
            var mapping = await _mappingService.InsertSurveyMappingAsync(userEmail, request);

            return(new ObjectResult(mapping)
            {
                StatusCode = 200
            });
        }