Пример #1
0
        public async Task <OperationResult> Delete(int innerResourceId)
        {
            try
            {
                var innerResource = new InnerResource()
                {
                    Id = innerResourceId
                };

                await innerResource.Delete(_dbContext);

                await _bus.SendLocal(new OuterInnerResourceDelete(new InnerResourceModel()
                {
                    Id = innerResourceId
                }, null));

                return(new OperationResult(true, _localizationService.GetString("InnerResourceDeletedSuccessfully")));
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                _logger.LogError(e.Message);
                return(new OperationResult(false,
                                           _localizationService.GetString("ErrorWhileDeletingInnerResource")));
            }
        }
        public async Task Machine_Delete_DoesDelete()
        {
            //Arrange
            InnerResource innerResource = new InnerResource
            {
                Name = Guid.NewGuid().ToString()
            };

            DbContext.InnerResources.Add(innerResource);
            DbContext.SaveChanges();

            //Act
            InnerResource selectedInnerResource = new InnerResource
            {
                Name = innerResource.Name,
                Id   = innerResource.Id
            };

            await selectedInnerResource.Delete(DbContext);

            InnerResource               dbInnerResource   = DbContext.InnerResources.AsNoTracking().First();
            List <InnerResource>        innerResourceList = DbContext.InnerResources.AsNoTracking().ToList();
            List <InnerResourceVersion> versionList       = DbContext.InnerResourceVersions.AsNoTracking().ToList();

            // Assert
            Assert.NotNull(dbInnerResource);
            Assert.AreEqual(1, innerResourceList.Count());
            Assert.AreEqual(1, versionList.Count());

            Assert.AreEqual(dbInnerResource.WorkflowState, Constants.WorkflowStates.Removed);
        }
        public void Machine_Delete_SetWorkflowStateToRemoved()
        {
            //Arrange

            InnerResource innerResource = new InnerResource();

            innerResource.Name = Guid.NewGuid().ToString();

            DbContext.InnerResources.Add(innerResource);
            DbContext.SaveChanges();

            //Act

            innerResource.Delete(DbContext);

            InnerResource               dbInnerResource = DbContext.InnerResources.AsNoTracking().First();
            List <InnerResource>        machinelList    = DbContext.InnerResources.AsNoTracking().ToList();
            List <InnerResourceVersion> machineVersions = DbContext.InnerResourceVersions.AsNoTracking().ToList();

            //Assert

            Assert.NotNull(dbInnerResource);
            Assert.NotNull(dbInnerResource.Id);

            Assert.AreEqual(1, machinelList.Count());
            Assert.AreEqual(1, machineVersions.Count());

            Assert.AreEqual(innerResource.CreatedAt.ToString(), dbInnerResource.CreatedAt.ToString());
            Assert.AreEqual(innerResource.Version, dbInnerResource.Version);
            Assert.AreEqual(innerResource.UpdatedAt.ToString(), dbInnerResource.UpdatedAt.ToString());
            Assert.AreEqual(innerResource.CreatedByUserId, dbInnerResource.CreatedByUserId);
            Assert.AreEqual(innerResource.UpdatedByUserId, dbInnerResource.UpdatedByUserId);
            Assert.AreEqual(innerResource.Name, dbInnerResource.Name);

            Assert.AreEqual(dbInnerResource.WorkflowState, Constants.WorkflowStates.Removed);
        }