Beispiel #1
0
        public async Task CreateShouldSucceed()
        {
            // Arrange
            var id          = Guid.NewGuid();
            var name        = "name";
            var description = "any description";
            var icon        = "iconUrl";
            var content     = "any content";
            var image       = "any imageUrl";
            var video       = "any videoUrl";
            var instruction = new Instruction(id, name, description, icon, content, image, video);
            var tag         = new Tag("tag");

            instruction.AddTag(tag);

            // Act
            await _repository.CreateAsync(instruction);

            // Assert
            var data = RepositoryHelper.ForInstruction.GetInstructions();

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

            result.Name.Should().Be(name);
            result.Description.Should().Be(description);
            result.Icon.Should().Be(icon);
            result.Content.Should().Be(content);
            result.Image.Should().Be(image);
            result.Video.Should().Be(video);
            result.Tags.Should().HaveCount(1);
            result.Tags.First().Should().Be(tag);
        }
Beispiel #2
0
        public async Task <Result> Handle(CreateInstructionCommand request, CancellationToken cancellationToken)
        {
            var id = _identifierProvider.Generate();
            var instructionToCreate = new Instruction(id, request.Name, request.Description, request.Icon, request.Content, request.Image, request.Video);

            foreach (var tag in request.Tags)
            {
                instructionToCreate.AddTag(new Tag(tag));
            }
            instructionToCreate.Version = _versionProvider.Generate();

            Result result;

            try
            {
                await _instructionWriteRepository.CreateAsync(instructionToCreate);

                result = Result.Ok(id, instructionToCreate.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.CreateInstructionFailure);
            }

            return(result);
        }