Ejemplo n.º 1
0
        public void ChangeAvatar()
        {
            // Arrange
            var diver = DiverFactory.CreateJaneDoe();

            // Act
            diver.ChangeAvatar("the_new_avatar_id");

            // Assert
            diver.AvatarId.Should().Be("the_new_avatar_id");
            diver.UncommittedDomainEvents.Should().ContainSingle(e => e.GetType() == typeof(AvatarChangedEvent));
        }
        public async Task Handle_OtherDiver_FailWithAccessDenied()
        {
            // Arrange
            A.CallTo(() => currentUser.GetCurrentDiverAsync())
            .ReturnsLazily(() => Task.FromResult(DiverFactory.CreateJaneDoe()));

            // Act
            var result = await interactor.Handle(editJohnDoeAvatarRequest, CancellationToken.None);

            // Assert
            result.IsSuccessful.Should().BeFalse();
            result.ResultCategory.Should().Be(ResultCategory.AccessDenied);
            A.CallTo(() => outputPort.Output(A <GetEditAvatarOutput> ._))
            .MustNotHaveHappened();
        }
        public async Task Handle_Admins_Success()
        {
            // Arrange
            A.CallTo(() => currentUser.GetCurrentDiverAsync())
            .ReturnsLazily(() => Task.FromResult(DiverFactory.CreateJaneDoe()));
            A.CallTo(() => currentUser.GetIsAdminAsync())
            .ReturnsLazily(() => Task.FromResult(true));

            // Act
            var result = await interactor.Handle(editJohnDoeAvatarRequest, CancellationToken.None);

            // Assert
            result.IsSuccessful.Should().BeTrue();
            A.CallTo(() => outputPort.Output(A <GetEditAvatarOutput> ._))
            .MustHaveHappenedOnceExactly();
        }
Ejemplo n.º 4
0
        public async Task Handle_NotCurrentDiverAndNotAdmin_MustReturnAccessDenied()
        {
            // Arrange
            var request = new EditAvatar(DiverFactory.JaneDoeDiverId, validAvatarFile);

            A.CallTo(() => diverRepository.FindByIdAsync(DiverFactory.JaneDoeDiverId))
            .ReturnsLazily(() => Task.FromResult(DiverFactory.CreateJaneDoe()));

            // Act
            var useCaseResult = await interactor.Handle(request, CancellationToken.None);

            // Assert
            useCaseResult.IsSuccessful.Should().BeFalse();
            useCaseResult.ResultCategory.Should().Be(ResultCategory.AccessDenied);
            A.CallTo(() => avatarStore.StoreAvatarAsync(
                         DiverFactory.JohnDoeFirstName,
                         A <string> ._,
                         A <string> ._,
                         A <Stream> ._)).MustNotHaveHappened();
        }
Ejemplo n.º 5
0
        public async Task Handle_NotCurrentDiverButAdmin_MustSucceed()
        {
            // Arrange
            var request = new EditAvatar(DiverFactory.JaneDoeDiverId, validAvatarFile);

            A.CallTo(() => diverRepository.FindByIdAsync(DiverFactory.JaneDoeDiverId))
            .ReturnsLazily(() => Task.FromResult(DiverFactory.CreateJaneDoe()));
            A.CallTo(() => currentUser.GetIsDiverOrAdmin(A <Guid> ._))
            .ReturnsLazily(() => Task.FromResult(true));

            // Act
            var useCaseResult = await interactor.Handle(request, CancellationToken.None);

            // Assert
            useCaseResult.IsSuccessful.Should().BeTrue();
            A.CallTo(() => avatarStore.StoreAvatarAsync(
                         DiverFactory.JaneDoeFirstName,
                         A <string> ._,
                         A <string> ._,
                         A <Stream> ._)).MustHaveHappenedOnceExactly();
        }