private bool Update(AssetOwnerEvent assetOwner) { AssetOwnerInfo existingAssetOwner = _assetOwnerRepository.GetExistingAssetOwner(assetOwner.AssetUID.Value); var compareResult = CheckExistingAssetOwnerForUpdate(existingAssetOwner, assetOwner); if (!compareResult) { Guid?customerUid = existingAssetOwner.CustomerUID == null ? (Guid?)null : new Guid(existingAssetOwner.CustomerUID); Guid?accountUid = existingAssetOwner.AccountUID == null? (Guid?)null : new Guid(existingAssetOwner.AccountUID); Guid?dealerUid = existingAssetOwner.DealerUID == null ? (Guid?)null : new Guid(existingAssetOwner.DealerUID); var assetOwnerEvent = new AssetOwnerEvent { AssetUID = assetOwner.AssetUID, AssetOwnerRecord = new ClientModel.AssetOwner { DealerUID = assetOwner.AssetOwnerRecord.DealerUID == null ? dealerUid : (assetOwner.AssetOwnerRecord.DealerUID == Guid.Empty ? null : assetOwner.AssetOwnerRecord.DealerUID), DealerName = assetOwner.AssetOwnerRecord.DealerName == null ? existingAssetOwner.DealerName : (string.IsNullOrWhiteSpace(assetOwner.AssetOwnerRecord.DealerName) ? null : assetOwner.AssetOwnerRecord.DealerName), CustomerName = assetOwner.AssetOwnerRecord.CustomerName == null ? existingAssetOwner.CustomerName : (string.IsNullOrWhiteSpace(assetOwner.AssetOwnerRecord.CustomerName) ? null : assetOwner.AssetOwnerRecord.CustomerName), AccountName = assetOwner.AssetOwnerRecord.AccountName == null ? existingAssetOwner.AccountName : (string.IsNullOrWhiteSpace(assetOwner.AssetOwnerRecord.AccountName) ? null : assetOwner.AssetOwnerRecord.AccountName), DealerAccountCode = assetOwner.AssetOwnerRecord.DealerAccountCode == null ? existingAssetOwner.DealerAccountCode : (string.IsNullOrWhiteSpace(assetOwner.AssetOwnerRecord.DealerAccountCode) ? null : assetOwner.AssetOwnerRecord.DealerAccountCode), NetworkCustomerCode = assetOwner.AssetOwnerRecord.NetworkCustomerCode == null ? existingAssetOwner.NetworkCustomerCode : (string.IsNullOrWhiteSpace(assetOwner.AssetOwnerRecord.NetworkCustomerCode) ? null : assetOwner.AssetOwnerRecord.NetworkCustomerCode), NetworkDealerCode = assetOwner.AssetOwnerRecord.NetworkDealerCode == null ? existingAssetOwner.NetworkDealerCode : (string.IsNullOrWhiteSpace(assetOwner.AssetOwnerRecord.NetworkDealerCode) ? null : assetOwner.AssetOwnerRecord.NetworkDealerCode), CustomerUID = assetOwner.AssetOwnerRecord.CustomerUID == null ? customerUid : (assetOwner.AssetOwnerRecord.CustomerUID == Guid.Empty ? null : assetOwner.AssetOwnerRecord.CustomerUID), AccountUID = assetOwner.AssetOwnerRecord.AccountUID == null ? accountUid : (assetOwner.AssetOwnerRecord.AccountUID == Guid.Empty ? null : assetOwner.AssetOwnerRecord.AccountUID) }, Action = Operation.Update, ActionUTC = DateTime.UtcNow, ReceivedUTC = DateTime.UtcNow }; return(_assetOwnerRepository.UpdateAssetOwnerEvent(assetOwnerEvent)); } return(compareResult); }
private void CreateAssetOwner_ExistAsset() { _assetOwnerService.CheckExistingAssetOwner(Arg.Any <Guid>()).Returns(true); _assetServices.ValidateAuthorizedCustomerByAsset(Arg.Any <Guid>(), Arg.Any <Guid>()).Returns(false); _assetOwnerService.CreateAssetOwnerEvent(Arg.Any <AssetOwnerEvent>()).Returns(true); _assetOwnerService.GetExistingAssetOwner(Arg.Any <Guid>()).Returns(x => new AssetOwnerInfo { AccountName = "CAT", AccountUID = "a162eb79-0317-11e9-a988-029d68d36a0c", CustomerName = "TDOO", CustomerUID = "a162eb79-0317-11e9-a988-029d68d36a0c", DealerAccountCode = "DEL23", DealerName = "DEL", DealerUID = "a162eb79-0317-11e9-a988-029d68d36a0c", NetworkCustomerCode = "412", NetworkDealerCode = "123" } ); _assetOwnerService.UpdateAssetOwnerEvent(Arg.Any <AssetOwnerEvent>()).Returns(true); var assetUID = new Guid("a162eb79-0317-11e9-a988-029d68d36a0c"); var response = _controller.AssetOwner(assetOwnerEvent); Assert.Equal(200, ((Microsoft.AspNetCore.Mvc.StatusCodeResult)response).StatusCode); }
public void Create_Update_Delete_AssetOwnerEvent() { //Arrange for Create var assetOwnerEvent = new AssetOwnerEvent() { Action = Operation.Create, ActionUTC = DateTime.UtcNow, AssetUID = new Guid(), AssetOwnerRecord = new VSS.MasterData.WebAPI.ClientModel.AssetOwner() { AccountName = "Sam", AccountUID = new Guid("a162eb79-0317-11e9-a988-029d68d36a0c"), CustomerName = "Cat", CustomerUID = new Guid("a162eb79-0317-11e9-a988-029d68d36a0d"), DealerAccountCode = "TD00", DealerName = "DemoDeler", DealerUID = new Guid("a162eb79-0317-11e9-a988-029d68d36a0e"), NetworkCustomerCode = "SAP", NetworkDealerCode = "TeT", } }; _transaction.Execute(Arg.Any <List <Action> >()).Returns(x => { foreach (var action in x.Arg <List <Action> >()) { action(); } return(true); }); //Act Assert.True(_assetOwnerServices.CreateAssetOwnerEvent(assetOwnerEvent)); //Arrange for Update assetOwnerEvent.Action = Operation.Update; //Act Assert.True(_assetOwnerServices.UpdateAssetOwnerEvent(assetOwnerEvent)); //Arrange for Delete assetOwnerEvent.Action = Operation.Delete; //Act Assert.True(_assetOwnerServices.DeleteAssetOwnerEvent(assetOwnerEvent)); }