示例#1
0
        public void CreateWithAlreadyExistingNameShouldFail()
        {
            // Arrange
            var id   = Guid.NewGuid();
            var name = "Load";

            RepositoryHelper.ForOperation.CreateOperation(id, name);

            var otherId   = Guid.NewGuid();
            var otherName = name;

            var otherTagName = "BSG";
            var otherTag     = new Tag(otherTagName);


            var operation = new Operation(otherId, otherName);


            operation.AddTag(otherTag);

            // Act
            Action act = () => { _repository.CreateAsync(operation).GetAwaiter().GetResult(); };

            // Assert
            act.Should().Throw <UniqueKeyException>();
        }
示例#2
0
 private static void UpdateOperationTags(Operation operation, List <RelTag> parentTag)
 {
     operation.Tags.ForEach(t => t.IsMarkForDeletion = true);
     foreach (var relTag in parentTag)
     {
         operation.AddTag(relTag.Tag);
     }
 }
示例#3
0
        private void BtnManualAccept_Click(object sender, RoutedEventArgs e)
        {
            _operation.SetTransaction(_cbTransaction.SelectedItem as TransactionType);
            _operation.SetTransfer(_cbTransfer.SelectedItem as TransferType);
            _operation.SetDate(DateTime.ParseExact(_labDate.Content.ToString(), Properties.strings.dateFormat, System.Globalization.CultureInfo.InvariantCulture));
            _operation.SetParent(_cbRelated.SelectedItem as OperationsGroup);
            _operation.SetDescription(_tbNewDescription.Text);
            _operation.SetShortDescription(_tbNewDescription.Text);
            _operation.SetAmount(_upDownAmount.Value);

            if (_operation.Parent != null)
            {
                _operation.SetImportance(_operation.Parent.Importance);
                _operation.SetFrequency(_operation.Parent.Frequency);
                _operation.RemoveAllTags();
                foreach (var item in _operation.Parent.Tags)
                {
                    _operation.AddTag(item.Tag);
                }
            }
            else
            {
                _operation.SetImportance(_cbImportance.SelectedItem as Importance);
                _operation.SetFrequency(_cbFrequent.SelectedItem as Frequency);
                _operation.RemoveAllTags();
                foreach (var item in _selectedTags)
                {
                    _operation.AddTag(item);
                }
            }

            try
            {
                Service.UpdateOperationComplex(_operation);
                ResetEditableControls();
                var operation = new Operation(null, null, Service.User, "", 0M, null, null, null, null, DateTime.Now, "");
                SetEditableControls();
                SetOperationValues(operation);
            }
            catch (Exception ex)
            {
                var dialog = new MessageBox(Properties.strings.messageBoxStatement, ex.Message);
                dialog.ShowDialog();
            }
        }
示例#4
0
        public void AddExistingTagShouldNotModifyCollection()
        {
            // Arrange
            var id      = Guid.NewGuid();
            var name    = "Operation";
            var entity  = new Operation(id, name);
            var tagName = "custom-tag";
            var tag     = new Tag(tagName);

            entity.AddTag(tag);

            // Act
            entity.AddTag(tag);

            // Assert
            entity.Tags.Count.Should().Be(1);
            entity.Tags.ElementAt(0).Name.Should().Be(tagName);
        }
        public async Task <Result> Handle(CreateOperationCommand request, CancellationToken cancellationToken)
        {
            var id = _identifierProvider.Generate();

            var operationToCreate = new Operation(id, request.Name);

            if (!string.IsNullOrWhiteSpace(request.Description))
            {
                operationToCreate.SetDescription(request.Description);
            }
            if (request.Icon != null)
            {
                var coloredIcon = new ColoredIcon(request.Icon.IconId, request.Icon.FillColor);
                operationToCreate.SetIcon(coloredIcon);
            }
            foreach (var tag in request.Tags)
            {
                operationToCreate.AddTag(new Tag(tag));
            }

            operationToCreate.Version = _versionProvider.Generate();


            Result result;

            try
            {
                await _operationWriteRepository.CreateAsync(operationToCreate);

                result = Result.Ok(id, operationToCreate.Version);
            }
            catch (UniqueKeyException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.Conflict,
                        Target  = "name"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.CreateOperationFailure);
            }

            return(result);
        }
示例#6
0
        public async Task CreateShouldSucceed()
        {
            // Arrange
            var id          = Guid.NewGuid();
            var name        = "name";
            var description = "description";
            var tag1Name    = "BSG";
            var tag1        = new Tag(tag1Name);
            var tag2Name    = "Chemicals";
            var tag2        = new Tag(tag2Name);

            var coloredIcon = new ColoredIcon(Guid.NewGuid(), "#45545645");
            var operation   = new Operation(id, name);

            operation.SetDescription(description);
            operation.SetIcon(coloredIcon);

            operation.AddTag(tag1);
            operation.AddTag(tag2);

            // Act
            await _repository.CreateAsync(operation);

            // Assert
            var data = RepositoryHelper.ForOperation.GetOperations();

            data.Should().HaveCount(1);
            var result = data.First();

            result.Name.Should().Be(name);
            result.Description.Should().Be(description);
            result.Icon.Should().Be(coloredIcon);
            result.Tags.Count.Should().Be(2);
            result.Tags.ElementAt(0).Should().Be(tag1);
            result.Tags.ElementAt(1).Should().Be(tag2);
        }
示例#7
0
        public void RemoveTagsShouldSucceed()
        {
            // Arrange
            var id      = Guid.NewGuid();
            var name    = "Operation";
            var entity  = new Operation(id, name);
            var tagName = "custom-tag";
            var tag     = new Tag(tagName);

            entity.AddTag(tag);

            // Act
            entity.ClearTags();

            // Assert
            entity.Tags.Count.Should().Be(0);
        }
示例#8
0
        public void RemoveUnexistingTagShouldPassSilentlyWithoutAnyImpactOnCollection()
        {
            // Arrange
            var id      = Guid.NewGuid();
            var name    = "Operation";
            var entity  = new Operation(id, name);
            var tagName = "custom-tag";
            var tag     = new Tag(tagName);

            entity.AddTag(tag);
            var tagToRemove = new Tag("TagToRemove");

            // Act
            entity.RemoveTag(tagToRemove);

            // Assert
            entity.Tags.Count.Should().Be(1);
            entity.Tags.ElementAt(0).Name.Should().Be(tagName);
        }