Ejemplo n.º 1
0
        public void FetchAssetConfig_ValidRequestWithFilterValueString_ValidQuery()
        {
            AssetSettingsDto request = new AssetSettingsDto
            {
                TargetValues = new Dictionary <AssetTargetType, Tuple <Guid, double> >
                {
                    { AssetTargetType.IdlingBurnRateinLiPerHour, new Tuple <Guid, double>(Guid.NewGuid(), 12) },
                    { AssetTargetType.WorkingBurnRateinLiPerHour, new Tuple <Guid, double>(Guid.NewGuid(), 22) }
                },
                FilterCriteria = new List <KeyValuePair <string, Tuple <string, object> > >
                {
                    new KeyValuePair <string, Tuple <string, object> >("LIKE", Tuple.Create <string, object>("a.AssetName", "fuel"))
                }
            };

            var result = _assetSettingsRepository.FetchAssetConfig(_assetUIDs, request).Result;

            var queryExpected = string.Format(
                AssetConfigRepository.Queries.FetchAssetConfig,
                string.Join(",", _assetUIDs.Select(x => "UNHEX('" + x + "')")).Replace("-", string.Empty),     //Asset UIDs Lists
                "a.AssetName LIKE 'fuel' AND ",
                string.Join(",", request.TargetValues.Keys.Select(x => string.Format("'{0}'", x.ToString())))
                );

            _transactions.Received(1).GetAsync <AssetSettingsDto>(Arg.Is <string>(queryExpected), Arg.Is <dynamic>(request));
        }
Ejemplo n.º 2
0
        public void AssociateCustomerAsset_ValidPayload_ExpectedTransactionStatus(
            bool hasValidCustomer, bool transactionStatus, int upsertCalls, int publishCalls, bool hasException,
            string relType)
        {
            //Arrange
            var customerUid        = Guid.NewGuid();
            var assetUid           = Guid.NewGuid();
            var assetCustomerEvent = new AssociateCustomerAssetEvent
            {
                CustomerUID  = customerUid,
                AssetUID     = assetUid,
                RelationType = relType,
                ActionUTC    = DateTime.UtcNow,
                ReceivedUTC  = DateTime.UtcNow
            };
            DbCustomer customerData = hasValidCustomer ? new DbCustomer()
            {
                CustomerID = 109
            } : null;

            transaction.Get <DbCustomer>(Arg.Any <string>()).Returns(new List <DbCustomer> {
                customerData
            });
            transaction.Execute(Arg.Any <List <Action> >())
            .Returns(a =>
            {
                if (hasException)
                {
                    a.Arg <List <Action> >().ForEach(action => action.Returns(e => throw new Exception()));
                    return(false);
                }
                else
                {
                    a.Arg <List <Action> >().ForEach(action => action.Invoke());
                    return(true);
                }
            });

            //Act
            var resultData = customerAssetService.AssociateCustomerAsset(assetCustomerEvent);

            //Assert
            Assert.Equal(transactionStatus, resultData);
            transaction.Received(upsertCalls).Upsert(
                Arg.Is <DbAssetCustomer>(assetCust => ValidateCustomerAssetObject(assetCustomerEvent, assetCust)));
            transaction.Received(publishCalls).Publish(
                Arg.Is <List <KafkaMessage> >(messages => messages
                                              .TrueForAll(m => ValidateCustomerAssetKafkaObject(false, m, assetCustomerEvent))));
        }
Ejemplo n.º 3
0
        public void ShouldAddWithdrawIntoTransactions()
        {
            DateTime          today            = DateTime.Now;
            ITransactions     transactions     = Substitute.For <ITransactions>();
            IBalanceRetriever balanceRetriever = Substitute.For <IBalanceRetriever>();
            var  bankingService = new BankingService(transactions, balanceRetriever);
            uint withdrawAmount = 200;

            bankingService.Withdraw(withdrawAmount, today);

            transactions.Received().Add(Arg.Is <ITransaction>(t => t.GetType() == typeof(Withdraw)));
        }
Ejemplo n.º 4
0
        public void AssociateCustomerUser_GivenPayload_ExpectedTransactionStatus(AssociateCustomerUserEvent userEvent,
                                                                                 bool hasValidCustomer, bool transactionStatus, int upsertCalls, int publishCalls, bool hasException)
        {
            //Arrange
            DbCustomer customerData = hasValidCustomer ? new DbCustomer()
            {
                CustomerID = 109
            } : null;

            if (hasException)
            {
                transaction.Get <DbCustomer>(Arg.Any <string>()).Returns(e => throw new Exception());
            }
            else
            {
                transaction.Get <DbCustomer>(Arg.Any <string>()).Returns(new List <DbCustomer> {
                    customerData
                });
            }
            transaction.Execute(Arg.Any <List <Action> >())
            .Returns(a =>
            {
                a.Arg <List <Action> >().ForEach(action => action.Invoke());
                return(true);
            });

            //Act
            if (hasException)
            {
                Assert.Throws <Exception>(() => userCustomerService.AssociateCustomerUser(userEvent));
            }
            else
            {
                var resultData = userCustomerService.AssociateCustomerUser(userEvent);

                Assert.Equal(transactionStatus, resultData);
            }

            //Assert
            transaction.Received(upsertCalls).Upsert(
                Arg.Is <DbUserCustomer>(userCust => ValidateCustomerUserObject(userEvent, userCust, customerData)));
            transaction.Received(publishCalls).Publish(
                Arg.Is <List <KafkaMessage> >(messages => messages
                                              .TrueForAll(m => ValidateCustomerUserKafkaObject(false, m, userEvent))));
        }
Ejemplo n.º 5
0
        public void FetchValidAssetUIds_ValidRequest_ValidQuery()
        {
            AssetSettingsListRequestDto request = new AssetSettingsListRequestDto
            {
                CustomerUid = Guid.NewGuid().ToString("N"),
                UserUid     = Guid.NewGuid().ToString("N")
            };

            _assetSettingsListRepository.FetchValidAssetUIds(_assetUIDs, request);

            _stubTransactions.Received(1).GetAsync <string>(Arg.Is <string>(string.Format(Queries.FetchAssetUIdsWithUserCustomerAndAssets,
                                                                                          string.Join(",", _assetUIDs.Select(x => "UNHEX('" + x + "')")).Replace("-", string.Empty))), Arg.Is <dynamic>(request));
        }
Ejemplo n.º 6
0
        public void GetCustomer_ValidCustomer_ReturnsData()
        {
            //Arrange
            var customerUid = Guid.NewGuid();
            var customer    = new DbCustomer
            {
                CustomerID          = 1,
                CustomerUID         = customerUid,
                CustomerName        = "CUS01",
                fk_CustomerTypeID   = 0,
                LastCustomerUTC     = DateTime.UtcNow,
                PrimaryContactEmail = "*****@*****.**",
                FirstName           = "FN01",
                LastName            = "LN01",
                NetworkDealerCode   = "NDC01",
                IsActive            = true
            };
            var config = new ComparisonConfig
            {
                IgnoreObjectTypes             = true,
                MaxMillisecondsDateDifference = 500,
                MaxDifferences = 0
            };
            var accountCompareLogic = new CompareLogic(config);

            transaction.Get <DbCustomer>(Arg.Any <string>()).Returns(new List <DbCustomer> {
                customer
            });

            //Act
            var resultData = customerService.GetCustomer(customerUid);

            //Arrange
            Assert.NotNull(resultData);
            transaction.Received(1)
            .Get <DbCustomer>(Arg.Is <string>(q => q.Contains($"UNHEX('{customerUid.ToString("N")}')")));
            ComparisonResult compareResult = accountCompareLogic.Compare(customer, resultData);

            Assert.True(compareResult.Differences.Count == 0);
        }
Ejemplo n.º 7
0
        public void TestCreateUserPreference_ValidInput_True()
        {
            //Arrange
            CreateUserPreferenceEvent createUser = new CreateUserPreferenceEvent()
            {
                PreferenceKeyUID  = new Guid("2ccfe195-81ec-4aed-ba31-fc7d794cb75f"),
                UserUID           = new Guid("85293f9c-b713-4e95-a5ed-b36beb2c4aa2"),
                PreferenceKeyName = "Key",
                PreferenceJson    = "Json",
                SchemaVersion     = "v1",
                ActionUTC         = DateTime.UtcNow
            };

            transaction.Get <PreferenceKeyDto>(Arg.Any <string>()).Returns(x => { return(new List <PreferenceKeyDto>()
                {
                    new PreferenceKeyDto()
                    {
                        PreferenceKeyID = 10, PreferenceKeyName = "Key", PreferenceKeyUID = createUser.PreferenceKeyUID.Value
                    }
                }); });

            //Act
            bool?result = preferenceService.CreateUserPreference(createUser);

            //Assert
            Assert.True(result);
            transaction.Received(1).Upsert <DbUserPreference>(Arg.Is <DbUserPreference>(x => x.fk_UserUID == createUser.UserUID));
            transaction.Received(1).Publish(Arg.Is <KafkaMessage>(x => x.Key == createUser.UserUID.ToString()));
            transaction.Received(1).Execute(Arg.Any <List <Action> >());
        }
Ejemplo n.º 8
0
        public void CreateAccount_ValidPayload_TransactionSuccess()
        {
            //Arrange
            var accountEvent = new CreateCustomerEvent
            {
                CustomerName        = "ACC01",
                CustomerUID         = Guid.NewGuid(),
                BSSID               = "BSS01",
                DealerAccountCode   = "DAC01",
                NetworkCustomerCode = "NCC01",
                ActionUTC           = DateTime.UtcNow,
                ReceivedUTC         = DateTime.UtcNow
            };

            transaction.Execute(Arg.Any <List <Action> >())
            .Returns(a =>
            {
                a.Arg <List <Action> >().ForEach(action => action.Invoke());
                return(true);
            });

            //Act
            var resultData = accountService.CreateAccount(accountEvent);

            //Assert
            Assert.True(resultData);
            transaction.Received(1).Upsert(Arg.Is <DbAccount>(o => ValidateAccountObject(accountEvent, o, false, null)));
            transaction.Received(1).Publish(
                Arg.Is <KafkaMessage>(m => ValidateAccountKafkaObject(accountEvent, m, false, null)));
        }