Example #1
0
        public void DeleteAsset()
        {
            _assetServices.GetAsset(Arg.Any <Guid>()).Returns(x => new VSS.MasterData.WebAPI.ClientModel.Asset {
                StatusInd = 1, AssetName = "EWR"
            });
            _assetServices.DeleteAsset(Arg.Any <DeleteAssetPayload>()).Returns(true);
            var response = _controller.DeleteAsset(Guid.NewGuid(), DateTime.Now);

            Assert.Equal(200, ((Microsoft.AspNetCore.Mvc.ObjectResult)response).StatusCode);
        }
Example #2
0
        public ActionResult DeleteAsset(Guid?AssetUID, DateTime?ActionUTC)
        {
            if (AssetUID == Guid.Empty || AssetUID == null || !Guid.TryParse(AssetUID.ToString(), out Guid g))
            {
                return(BadRequest("AssetUID field values must be valid"));
            }
            try
            {
                var assetDetails = _assetService.GetAsset(AssetUID.Value);

                if (assetDetails == null || assetDetails.StatusInd == 0)
                {
                    return(BadRequest("Asset does not exist"));
                }

                var asset = new DeleteAssetPayload
                {
                    AssetUID    = AssetUID.Value,
                    ActionUTC   = DateTime.UtcNow,
                    ReceivedUTC = DateTime.UtcNow
                };

                if (_assetService.DeleteAsset(asset))
                {
                    return(Ok(asset.AssetUID.ToString()));
                }
                return(BadRequest("Unable to save to db. Make sure request is not duplicated and all keys exist"));
            }

            catch (Exception ex)
            {
                _logger.LogError(" Delete Asset Exception: " + ex.Message);
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Example #3
0
        public void Delete_Asset()
        {
            //Arrange for Create

            var assetObject = new DeleteAssetPayload()
            {
                AssetUID    = Guid.NewGuid(),
                ActionUTC   = DateTime.UtcNow,
                ReceivedUTC = DateTime.UtcNow,
            };

            _transaction.Execute(Arg.Any <List <Action> >()).Returns(x =>
            {
                foreach (var action in x.Arg <List <Action> >())
                {
                    action();
                }
                return(true);
            });

            //Act
            Assert.True(_assetServices.DeleteAsset(assetObject));
        }