示例#1
0
        public async Task Creating_An_Uncreatable_Space_Fails()
        {
            // arrange
            var spaceRepository = new Mock <ISpaceRepository>();

            spaceRepository.Setup(c => c.Add(It.IsAny <ISpace>()))
            .Throws(new UnableToCreateSpaceException("nah", new Exception()));

            var entityFactory = new InMemoryEntityFactory();
            var spaceService  = new SpaceService(entityFactory, spaceRepository.Object);

            var createSpacePresenter = new CreateSpacePresenter();

            var useCase = new Application.UseCases.CreateSpace(createSpacePresenter, spaceService);
            var input   = new CreateSpaceInput(new SpaceName("Demo"));

            // act
            await useCase.Execute(input);

            // assert
            Assert.Single(createSpacePresenter.UnableToCreate);
            Assert.Empty(createSpacePresenter.CreatedSpaces);
            Assert.Empty(createSpacePresenter.AlreadyExisting);

            spaceRepository.Verify(c => c.Add(It.Is <ISpace>(s => s.Name.ToString() == "Demo")));
            spaceRepository.VerifyNoOtherCalls();
        }
示例#2
0
        public async Task Space_Is_Retrievable_After_Creation()
        {
            var createSpacePresenter = new CreateSpacePresenter();
            var useCase = new Application.UseCases.CreateSpace(createSpacePresenter, _spaceService);

            var input = new CreateSpaceInput(new SpaceName("Demo"));
            await useCase.Execute(input);

            Assert.Single(createSpacePresenter.CreatedSpaces);

            ISpace createdSpace = await _spaceRepository.Get(new SpaceName("Demo"));

            Assert.Equal("Demo", createdSpace.Name.ToString());
        }
示例#3
0
        public async Task New_Space_Should_Be_Creatable()
        {
            var createSpacePresenter = new CreateSpacePresenter();
            var useCase = new Application.UseCases.CreateSpace(createSpacePresenter, _spaceService);

            var input = new CreateSpaceInput(new SpaceName("Demo"));
            await useCase.Execute(input);

            var createdSpace = createSpacePresenter.CreatedSpaces.Single().Space;

            Assert.NotNull(createdSpace);
            Assert.Equal(input.SpaceName, createdSpace.Name);
            Assert.Empty(createSpacePresenter.AlreadyExisting);
            Assert.Empty(createSpacePresenter.UnableToCreate);
        }
示例#4
0
        public async Task Creating_The_Same_Space_Twice_Already_Exists()
        {
            var createSpacePresenter = new CreateSpacePresenter();

            var useCase1 = new Application.UseCases.CreateSpace(createSpacePresenter, _spaceService);
            var input1   = new CreateSpaceInput(new SpaceName("Demo"));
            await useCase1.Execute(input1);

            var useCase2 = new Application.UseCases.CreateSpace(createSpacePresenter, _spaceService);
            var input2   = new CreateSpaceInput(new SpaceName("Demo"));
            await useCase2.Execute(input2);

            Assert.Single(createSpacePresenter.CreatedSpaces);
            Assert.Single(createSpacePresenter.AlreadyExisting);
            Assert.Empty(createSpacePresenter.UnableToCreate);
        }
示例#5
0
        /// <inheritdoc/>
        public async Task Execute(CreateSpaceInput input)
        {
            try
            {
                ISpace space = await _spaceService.CreateSpace(input.SpaceName);

                _outputPort.Standard(new CreateSpaceOutput(space));
            }
            catch (SpaceAlreadyExistsException e)
            {
                _outputPort.SpaceAlreadyExists(e.Message);
            }
            catch (UnableToCreateSpaceException e)
            {
                _outputPort.UnableToCreateSpace(e.Message);
            }
        }
示例#6
0
 /// <summary>
 /// Creates the space with the given name.
 /// </summary>
 /// <param name="name">The name of the new space to create.</param>
 /// <returns>Task.</returns>
 public async Task CreateSpace(SpaceName name)
 {
     var input = new CreateSpaceInput(name);
     await _mediator.PublishAsync(input);
 }