Exemple #1
0
        /// <summary>
        /// Creates the inventory tag.
        /// </summary>
        /// <param name="requestModel">The request model.</param>
        /// <returns>Task&lt;OperationResult&gt;.</returns>
        public async Task <OperationResult> CreateInventoryTag(CommonTagModel requestModel)
        {
            try
            {
                var inventoryTag = new InventoryTag
                {
                    Name            = requestModel.Name,
                    CreatedByUserId = _userService.UserId,
                    UpdatedByUserId = _userService.UserId,
                };

                await inventoryTag.Create(_dbContext);

                return(new OperationResult(
                           true,
                           _inventoryLocalizationService.GetString("InventoryTagCreatedSuccessfully")));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                _logger.LogError(e.Message);
                return(new OperationResult(
                           false,
                           _inventoryLocalizationService.GetString("ErrorWhileCreatingInventoryTag")));
            }
        }
        public async Task InventoryTag_Update_DoesUpdate()
        {
            // Arrange
            var inventoryTag = new InventoryTag
            {
                Name            = Guid.NewGuid().ToString(),
                CreatedByUserId = 1,
                UpdatedByUserId = 1,
            };

            // Act
            await inventoryTag.Create(DbContext);

            var oldInventoryTagsList = DbContext.InventoryTags
                                       .AsNoTracking()
                                       .First();

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

            await inventoryTag.Update(DbContext);


            var inventoryTagFromDb = DbContext.InventoryTags
                                     .AsNoTracking()
                                     .First(x => x.Id == inventoryTag.Id);

            var inventoryTagsListVersions = DbContext.InventoryTagVersions
                                            .AsNoTracking()
                                            .ToList();


            // Assert
            Assert.AreEqual(inventoryTag.CreatedByUserId, inventoryTagFromDb.CreatedByUserId);
            Assert.AreEqual(inventoryTag.UpdatedByUserId, inventoryTagFromDb.UpdatedByUserId);
            Assert.AreEqual(inventoryTag.Name, inventoryTagFromDb.Name);
            Assert.AreEqual(inventoryTag.Id, inventoryTagFromDb.Id);
            Assert.AreEqual(2, inventoryTagFromDb.Version);
            Assert.AreEqual(inventoryTag.WorkflowState, inventoryTagFromDb.WorkflowState);

            // versions
            Assert.AreEqual(2, inventoryTagsListVersions.Count);
            Assert.AreEqual(oldInventoryTagsList.CreatedByUserId, inventoryTagsListVersions[0].CreatedByUserId);
            Assert.AreEqual(oldInventoryTagsList.UpdatedByUserId, inventoryTagsListVersions[0].UpdatedByUserId);
            Assert.AreEqual(oldInventoryTagsList.Name, inventoryTagsListVersions[0].Name);
            Assert.AreEqual(oldInventoryTagsList.Id, inventoryTagsListVersions[0].InventoryTagId);
            Assert.AreEqual(oldInventoryTagsList.WorkflowState, inventoryTagsListVersions[0].WorkflowState);
            Assert.AreEqual(1, inventoryTagsListVersions[0].Version);

            Assert.AreEqual(inventoryTag.CreatedByUserId, inventoryTagsListVersions[1].CreatedByUserId);
            Assert.AreEqual(inventoryTag.UpdatedByUserId, inventoryTagsListVersions[1].UpdatedByUserId);
            Assert.AreEqual(inventoryTag.Name, inventoryTagsListVersions[1].Name);
            Assert.AreEqual(inventoryTag.Id, inventoryTagsListVersions[1].InventoryTagId);
            Assert.AreEqual(inventoryTag.WorkflowState, inventoryTagsListVersions[1].WorkflowState);
            Assert.AreEqual(2, inventoryTagsListVersions[1].Version);
        }
        public async Task InventoryTag_Save_DoesSave()
        {
            // Arrange
            var inventoryTag = new InventoryTag
            {
                Name            = Guid.NewGuid().ToString(),
                CreatedByUserId = 1,
                UpdatedByUserId = 1,
            };

            // Act
            await inventoryTag.Create(DbContext);


            var inventoryTagsList = DbContext.InventoryTags
                                    .AsNoTracking()
                                    .ToList();

            var inventoryTagsListVersions = DbContext.InventoryTagVersions
                                            .AsNoTracking()
                                            .ToList();


            // Assert
            Assert.AreEqual(1, inventoryTagsList.Count);
            Assert.AreEqual(inventoryTag.CreatedByUserId, inventoryTagsList[0].CreatedByUserId);
            Assert.AreEqual(inventoryTag.UpdatedByUserId, inventoryTagsList[0].UpdatedByUserId);
            Assert.AreEqual(inventoryTag.Name, inventoryTagsList[0].Name);
            Assert.AreEqual(inventoryTag.Id, inventoryTagsList[0].Id);
            Assert.AreEqual(1, inventoryTagsList[0].Version);
            Assert.AreEqual(Constants.WorkflowStates.Created, inventoryTagsList[0].WorkflowState);
            Assert.AreEqual(inventoryTag.WorkflowState, inventoryTagsList[0].WorkflowState);


            // versions
            Assert.AreEqual(1, inventoryTagsListVersions.Count);
            Assert.AreEqual(inventoryTag.CreatedByUserId, inventoryTagsListVersions[0].CreatedByUserId);
            Assert.AreEqual(inventoryTag.UpdatedByUserId, inventoryTagsListVersions[0].UpdatedByUserId);
            Assert.AreEqual(inventoryTag.Name, inventoryTagsListVersions[0].Name);
            Assert.AreEqual(inventoryTag.Id, inventoryTagsListVersions[0].InventoryTagId);
            Assert.AreEqual(Constants.WorkflowStates.Created, inventoryTagsListVersions[0].WorkflowState);
            Assert.AreEqual(inventoryTag.WorkflowState, inventoryTagsListVersions[0].WorkflowState);
            Assert.AreEqual(1, inventoryTagsListVersions[0].Version);
        }