Пример #1
0
        public void TestUpdatePreferenceKey_ValidInput_True()
        {
            //Arrange
            UpdatePreferenceKeyEvent updatePreference = new UpdatePreferenceKeyEvent()
            {
                PreferenceKeyUID  = new Guid("2ae9019e-b840-4121-8639-366eecac91c1"),
                PreferenceKeyName = "Key",
                ActionUTC         = DateTime.UtcNow
            };
            var dbPreferenceKey = new PreferenceKeyDto()
            {
                PreferenceKeyUID  = new Guid("2ae9019e-b840-4121-8639-366eecac91c1"),
                PreferenceKeyName = "Key",
                InsertUTC         = DateTime.UtcNow.AddDays(-1),
                UpdateUTC         = DateTime.UtcNow
            };

            transaction.Get <PreferenceKeyDto>(Arg.Is <string>(x => x.Contains("PreferenceKeyUID"))).Returns(x => { return(new List <PreferenceKeyDto>()
                {
                    dbPreferenceKey
                }); });

            //Act
            bool?result = preferenceService.UpdatePreferenceKey(updatePreference);

            //Assert
            Assert.True(result);
            transaction.Received(2).Get <PreferenceKeyDto>(Arg.Any <string>());
            transaction.Received(1).Upsert(Arg.Is <DbPreferenceKey>(x => x.PreferenceKeyUID == updatePreference.PreferenceKeyUID && x.PreferenceKeyName == updatePreference.PreferenceKeyName));
            transaction.Received(1).Publish(Arg.Is <KafkaMessage>(x => x.Key == updatePreference.PreferenceKeyUID.ToString()));
            transaction.Received(1).Execute(Arg.Any <List <Action> >());
        }
Пример #2
0
        public ActionResult UpdatePreferenceKey([FromBody] UpdatePreferenceKeyEvent preferenceEvent)
        {
            try
            {
                bool?isSuccess = _preferenceService.UpdatePreferenceKey(preferenceEvent);
                if (isSuccess.HasValue && isSuccess == true)
                {
                    return(Ok());
                }
                else if (isSuccess == null)
                {
                    logger.LogError("PreferenceKey does not exist");
                    return(BadRequest("PreferenceKey does not exist"));
                }

                logger.LogError("Unable to save to db. Make sure request is not duplicated and all keys exist");
                return(BadRequest("Unable to save to db. Make sure request is not duplicated and all keys exist"));
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("PreferenceKey Name Already Exist"))
                {
                    return(BadRequest("PreferenceKey Name Already Exist"));
                }

                logger.LogError(ex.Message + ex.StackTrace);
                return(StatusCode(500, ex.Message));
            }
        }