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 Check_ExistingAssetOwner(string avail, bool isExist) { //Arrange _transaction.Get <string>(Arg.Any <string>()).Returns(x => { return(new List <string>() { avail }); }); //Act var result = _assetOwnerServices.CheckExistingAssetOwner(new Guid()); //Assert Assert.Equal(result, isExist); }
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); }