Exemplo n.º 1
0
        public void TestInteractor__MotorcycleRepositoryIsNull()
        {
            // ARRANGE
            var authServiceMock = new Mock <IAuthService>();

            // ACT
            (_, IError error) = PostMotorcycleInteractor.NewPostMotorcycleInteractor(null, authServiceMock.Object);


            // ASSERT
            Assert.NotNull(error);
        }
Exemplo n.º 2
0
        public async Task TestInteractor_NotAuthenticated()
        {
            // ARRANGE
            var authServiceMock = new Mock <IAuthService>();

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

            (PostMotorcycleRequest request, _) = PostMotorcycleRequest.NewPostMotorcycleRequest("Honda", "Shadow", 2006, "01234567890123456");

            (PostMotorcycleInteractor interactor, _) = PostMotorcycleInteractor.NewPostMotorcycleInteractor(repositoryMock.Object, authServiceMock.Object);

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

            // ASSERT
            Assert.NotNull(error);
        }
Exemplo n.º 3
0
        public void TestInteractor_AuthServiceIsNull()
        {
            // ARRANGE
            //            var roles = new Dictionary<AuthorizationRole, bool>
            //            {
            //                {
            //                    AuthorizationRole.None, true
            //                }
            //            };

            var repositoryMock = new Mock <IMotorcycleRepository>();

            // ACT
            (_, IError error) = PostMotorcycleInteractor.NewPostMotorcycleInteractor(repositoryMock.Object, null);


            // ASSERT
            Assert.NotNull(error);
        }
Exemplo n.º 4
0
        public async Task TestInteractor_VinAlreadyExists()
        {
            // 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>();

            var tcsExists = new TaskCompletionSource <(bool, OperationStatus, IError)>();

            tcsExists.SetResult((false, OperationStatus.NotFound, null));
            repositoryMock.Setup(r => r.ExistsByIdAsync(It.IsAny <long>())).Returns(tcsExists.Task);

            var tcsInsert = new TaskCompletionSource <(Motorcycle, OperationStatus, IError)>();

            tcsInsert.SetResult((motorcycle, OperationStatus.Ok, null));
            repositoryMock.Setup(r => r.InsertAsync(It.IsAny <Motorcycle>(), It.IsAny <Func <Motorcycle, Task <(bool exists, OperationStatus status, IError error)> > >())).Returns(tcsInsert.Task);

            // Create the request to add a new motorcycle to the repository.
            var(request, _) = PostMotorcycleRequest.NewPostMotorcycleRequest("Honda", "Shadow", 2006, "01234567890123456");

            // Create the interactor that will coordinate adding a new motorcycle to the repository.
            (PostMotorcycleInteractor interactor, _) = PostMotorcycleInteractor.NewPostMotorcycleInteractor(repositoryMock.Object, authServiceMock.Object);

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

            // ASSERT
            Assert.True(response.Id > Domain.Constants.InvalidEntityId);
            Assert.Null(response.Error);
        }