private OutboundJsonWebTokenPayload CreateTokenPayload() => new OutboundJsonWebTokenPayload
 {
     IssuedAtTime = jwtService.GetIssuedAtTime().ToString(CultureInfo.InvariantCulture),
     Expiry       = outboundSynchronisationDataService.GetExpiry(),
     NotBefore    = outboundSynchronisationDataService.GetNotBeforeTime(),
     Issuer       = "msd"
 };
        private OutboundJsonWebTokenPayload CreateTokenPayload()
        {
            var payload = new OutboundJsonWebTokenPayload
            {
                Expiry    = outboundSynchronisationDataService.GetExpiry(),
                NotBefore = outboundSynchronisationDataService.GetNotBeforeTime()
            };

            return(payload);
        }
Beispiel #3
0
        public void GetExpiryTest()
        {
            var expectedResult = "100";

            crmService = new TestCrmService(crmServiceHelper.GetExpiry);
            outboundSynchronisationDataService = new OutboundSynchronisationDataService(this.logger, this.crmService);
            var actualResult = outboundSynchronisationDataService.GetExpiry();

            Assert.IsNotNull(actualResult);
            Assert.AreEqual(expectedResult, actualResult);
        }
Beispiel #4
0
        public void TestCreateSuccessResponse()
        {
            // Given
            var payload     = "payload";
            var entityCache = new List <EntityCache>()
            {
                new EntityCache()
                {
                    SourceMarket   = "sm1",
                    Data           = "{'Fields':[{'Name':'territorycode','Type':8,'Value':{'__type':'OptionSet','Name':null,'Value':1}}]}",
                    Id             = Guid.NewGuid(),
                    Name           = "name1",
                    Operation      = EntityCacheOperation.Create,
                    RecordId       = "id1",
                    SourceSystemId = "ssId1",
                    Type           = "type1",
                    RequestsCount  = 1
                }
            };
            var entityCacheMessage = new EntityCacheMessage()
            {
                EntityCacheId = entityCache[0].Id,
                Name          = string.Format(entityCacheMessageName, entityCache[0].RecordId, entityCache[0].Id)
            };
            var messageGuid    = Guid.NewGuid();
            var responseEntity = new Crm.Common.IntegrationLayer.Model.ResponseEntity()
            {
                StatusCode = HttpStatusCode.Created,
                Content    = "content",
                Cookies    = new Dictionary <string, string>()
            };

            A.CallTo(() => outboundSynchDataService.GetCreatedEntityCacheToProcess(entityName, batchSize)).Returns(entityCache);
            A.CallTo(() => outboundSynchDataService.GetSecretKey()).Returns(secretKey);
            A.CallTo(() => jwtService.GetIssuedAtTime()).Returns(issuedAtTime);
            A.CallTo(() => outboundSynchDataService.GetExpiry()).Returns(expiry);
            A.CallTo(() => outboundSynchDataService.GetNotBeforeTime()).Returns(notBeforeTime);

            A.CallTo(() => jwtService.CreateJwtToken(
                         secretKey,
                         A <OutboundJsonWebTokenPayload> .That.Matches(el => el.Issuer == "msd" && el.Expiry == expiry && el.IssuedAtTime == issuedAtTime.ToString(CultureInfo.InvariantCulture) && el.NotBefore == notBeforeTime)))
            .Returns(jwtToken);

            A.CallTo(() => outboundSynchDataService.CreateEntityCacheMessage(A <EntityCacheMessage> .That.Matches(el => el.Name == entityCacheMessage.Name))).Returns(messageGuid);
            A.CallTo(() => createRequestPayloadCreator.GetPayload(A <Crm.Common.IntegrationLayer.Model.EntityModel> ._)).Returns(payload);
            A.CallTo(() => jwtService.SendHttpRequest(HttpMethod.Post, createServiceUrl, jwtToken, payload, messageGuid.ToString())).Returns(responseEntity);

            // When
            outboundSynchService.ProcessEntityCacheOperation(Operation.Create);

            // Then
            A.CallTo(() => logger.LogInformation($"Processing {Enum.GetName(typeof(EntityCacheMessageStatusReason), Operation.Create)} EntityCache for entity: {entityName}")).MustHaveHappened();
            A.CallTo(() => logger.LogInformation($"Integration layer endpoint: {createServiceUrl}")).MustHaveHappened();
            A.CallTo(() => logger.LogInformation($"Retrieving entity cache records to process with maximum batch size: {batchSize}")).MustHaveHappened();
            A.CallTo(() => logger.LogInformation("Found 1 records to be processed")).MustHaveHappened();
            A.CallTo(() => logger.LogInformation($"Executed call to integration layer.  EntityCacheMessage Status Reason: {Enum.GetName(typeof(EntityCacheMessageStatusReason), EntityCacheMessageStatusReason.SuccessfullySentToIL)}")).MustHaveHappened();

            A.CallTo(() => outboundSynchDataService.UpdateEntityCacheStatus(entityCache[0].Id, Status.Active, EntityCacheStatusReason.InProgress)).MustHaveHappened();
            A.CallTo(() => outboundSynchDataService.UpdateEntityCacheMessageStatus(messageGuid, Status.Inactive, EntityCacheMessageStatusReason.SuccessfullySentToIL, A <string> ._)).MustHaveHappened();
            A.CallTo(() => outboundSynchDataService.UpdateEntityCacheSendToIntegrationLayerStatus(entityCache[0].Id, true, null)).MustHaveHappened();
        }