public ActionResult GetAssetOwner(Guid assetUID) { try { if (assetUID == Guid.Empty) { _logger.LogInformation($"AssetUID is mandatory AssetUID :{assetUID}"); return(BadRequest("AssetUID is mandatory")); } var userGuid = GetUserContext(); if (userGuid == null || !userGuid.HasValue || _assetServices.ValidateAuthorizedCustomerByAsset(userGuid.Value, assetUID)) { _logger.LogInformation(string.Format("Unauthorized User Access-Get AssetOwner called for {0}", assetUID)); return(BadRequest("Unauthorized User Access")); } if (!_assetOwnerRepository.CheckExistingAssetOwner(assetUID)) { _logger.LogInformation($"AssetUID does not exist AssetUID:{assetUID}"); return(BadRequest("No Such AssetUID exist")); } var existingAssetOwner = _assetOwnerRepository.GetExistingAssetOwner(assetUID); return(Ok(existingAssetOwner)); } catch (Exception ex) { _logger.LogError(ex.Message + ex.StackTrace); return(StatusCode((int)HttpStatusCode.InternalServerError)); } }
public void Get_Valid_GetAssetOwner() { //Arrange _assetOwnerService.CheckExistingAssetOwner(Arg.Any <Guid>()).Returns(true); _assetServices.ValidateAuthorizedCustomerByAsset(Arg.Any <Guid>(), Arg.Any <Guid>()).Returns(false); _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" } ); var assetUID = new Guid("a162eb79-0317-11e9-a988-029d68d36a0c"); //Act var response = _controller.GetAssetOwner(assetUID); //Assert Assert.Equal(200, ((Microsoft.AspNetCore.Mvc.ObjectResult)response).StatusCode); Assert.Equal("CAT", ((VSS.MasterData.WebAPI.DbModel.AssetOwnerInfo)((Microsoft.AspNetCore.Mvc.ObjectResult)response).Value).AccountName); Assert.Equal("412", ((VSS.MasterData.WebAPI.DbModel.AssetOwnerInfo)((Microsoft.AspNetCore.Mvc.ObjectResult)response).Value).NetworkCustomerCode); Assert.Equal("123", ((VSS.MasterData.WebAPI.DbModel.AssetOwnerInfo)((Microsoft.AspNetCore.Mvc.ObjectResult)response).Value).NetworkDealerCode); Assert.Equal("TDOO", ((VSS.MasterData.WebAPI.DbModel.AssetOwnerInfo)((Microsoft.AspNetCore.Mvc.ObjectResult)response).Value).CustomerName); Assert.Equal("DEL", ((VSS.MasterData.WebAPI.DbModel.AssetOwnerInfo)((Microsoft.AspNetCore.Mvc.ObjectResult)response).Value).DealerName); Assert.Equal("a162eb79-0317-11e9-a988-029d68d36a0c", ((VSS.MasterData.WebAPI.DbModel.AssetOwnerInfo)((Microsoft.AspNetCore.Mvc.ObjectResult)response).Value).CustomerUID); Assert.Equal("a162eb79-0317-11e9-a988-029d68d36a0c", ((VSS.MasterData.WebAPI.DbModel.AssetOwnerInfo)((Microsoft.AspNetCore.Mvc.ObjectResult)response).Value).DealerUID); }
public void Get_ExistingAssetOwner() { //Arrange _transaction.Get <AssetOwnerInfo>(Arg.Any <string>()).Returns(x => { return(new List <AssetOwnerInfo> () { new AssetOwnerInfo() { AccountName = "Sam", AccountUID = "a162eb79-0317-11e9-a988-029d68d36a0c", CustomerName = "Cat", CustomerUID = "a162eb79-0317-11e9-a988-029d68d36a0d", DealerAccountCode = "TD00", DealerName = "DemoDeler", DealerUID = "a162eb79-0317-11e9-a988-029d68d36a0e", NetworkCustomerCode = "SAP", NetworkDealerCode = "TeT" } }); }); //Act var result = _assetOwnerServices.GetExistingAssetOwner(new Guid()); //Assert Assert.Equal("TeT", result.NetworkDealerCode); Assert.Equal("Sam", result.AccountName); Assert.Equal("a162eb79-0317-11e9-a988-029d68d36a0c", result.AccountUID); Assert.Equal("Cat", result.CustomerName); Assert.Equal("a162eb79-0317-11e9-a988-029d68d36a0d", result.CustomerUID); Assert.Equal("TD00", result.DealerAccountCode); Assert.Equal("DemoDeler", result.DealerName); Assert.Equal("a162eb79-0317-11e9-a988-029d68d36a0e", result.DealerUID); Assert.Equal("SAP", result.NetworkCustomerCode); }