Esempio n. 1
0
        public async Task TestInteractor_NotExist()
        {
            // ARRANGE
            //   Authorization Service Mocking
            var authServiceMock = new Mock <IAuthService>();

            authServiceMock.Setup(d => d.IsAuthenticated())
            .Returns(true);
            authServiceMock.Setup(d => d.IsAuthorized(AuthorizationRole.Admin))
            .Returns(true);

            //   Repository Mocking
            var repositoryMock = new Mock <IMotorcycleRepository>();

            //    Repository Delete Mocking
            var deleteTcs = new TaskCompletionSource <(OperationStatus, IError)>();

            deleteTcs.SetResult((OperationStatus.NotFound, new Error("Does not exist.")));
            repositoryMock.Setup(d => d.DeleteAsync(It.IsAny <long>()))
            .Returns(deleteTcs.Task);
            var(request, _) = DeleteMotorcycleRequest.NewDeleteMotorcycleRequest(123);

            (DeleteMotorcycleInteractor interactor, _) = DeleteMotorcycleInteractor.NewDeleteMotorcycleInteractor(repositoryMock.Object, authServiceMock.Object);

            // ACT
            (_, IError error) = await interactor.HandleAsync(request);

            // ASSERT
            Assert.NotNull(error);
        }
Esempio n. 2
0
        public async Task TestInteractor_Delete()
        {
            // ARRANGE
            //   Authorization Service Mocking
            var authServiceMock = new Mock <IAuthService>();

            authServiceMock.Setup(d => d.IsAuthenticated())
            .Returns(true);
            authServiceMock.Setup(d => d.IsAuthorized(AuthorizationRole.Admin))
            .Returns(true);

            //   Repository Mocking
            (Motorcycle motorcycle, _) = Motorcycle.NewMotorcycle("Honda", "Shadow", 2006, "01234567890123456");
            motorcycle.Id = 1;
            var repositoryMock = new Mock <IMotorcycleRepository>();

            //    Repository Delete Mocking
            var deleteTcs = new TaskCompletionSource <(OperationStatus, IError)>();

            deleteTcs.SetResult((OperationStatus.Ok, null));
            repositoryMock.Setup(d => d.DeleteAsync(It.IsAny <long>()))
            .Returns(deleteTcs.Task);
            var(request, _) = DeleteMotorcycleRequest.NewDeleteMotorcycleRequest(motorcycle.Id);

            (DeleteMotorcycleInteractor interactor, _) = DeleteMotorcycleInteractor.NewDeleteMotorcycleInteractor(repositoryMock.Object, authServiceMock.Object);

            // ACT
            (DeleteMotorcycleResponse response, _) = await interactor.HandleAsync(request);

            // ASSERT
            Assert.True(response.Id == motorcycle.Id);
        }
Esempio n. 3
0
        public async Task TestInteractor_NotAuthenticated()
        {
            // ARRANGE
            var authServiceMock = new Mock <IAuthService>();

            authServiceMock.Setup(d => d.IsAuthenticated()).Returns(false);
            var repositoryMock = new Mock <IMotorcycleRepository>();

            var(request, _) = DeleteMotorcycleRequest.NewDeleteMotorcycleRequest(123);

            (DeleteMotorcycleInteractor interactor, _) = DeleteMotorcycleInteractor.NewDeleteMotorcycleInteractor(repositoryMock.Object, authServiceMock.Object);

            // ACT
            (_, IError error) = await interactor.HandleAsync(request);

            // ASSERT
            Assert.NotNull(error);
        }