public async Task TestInteractor_NotEmptyList() { // 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 motorcycles = new List <Motorcycle> { motorcycle }; // Repository List Mocking var tcs = new TaskCompletionSource <(IReadOnlyCollection <Motorcycle>, OperationStatus, IError)>(); tcs.SetResult((motorcycles, OperationStatus.Ok, null)); repositoryMock.Setup(d => d.ListAsync()) .Returns(tcs.Task); var(request, _) = ListMotorcyclesRequest.NewListMotorcyclesRequest(); (ListMotorcyclesInteractor interactor, _) = ListMotorcyclesInteractor.NewListMotorcycleInteractor(repositoryMock.Object, authServiceMock.Object); // ACT (ListMotorcyclesResponse response, _) = await interactor.HandleAsync(request); // ASSERT Assert.True(response.Motorcycles.Count == 1); }
public void TestInteractor__MotorcycleRepositoryIsNull() { // ARRANGE var authServiceMock = new Mock <IAuthService>(); // ACT (_, IError error) = ListMotorcyclesInteractor.NewListMotorcycleInteractor(null, authServiceMock.Object); // ASSERT Assert.NotNull(error); }
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, _) = ListMotorcyclesRequest.NewListMotorcyclesRequest(); (ListMotorcyclesInteractor interactor, _) = ListMotorcyclesInteractor.NewListMotorcycleInteractor(repositoryMock.Object, authServiceMock.Object); // ACT (_, IError error) = await interactor.HandleAsync(request); // ASSERT Assert.NotNull(error); }
public void TestInteractor_AuthServiceIsNull() { // ARRANGE // var roles = new Dictionary<AuthorizationRole, bool> // { // { // AuthorizationRole.None, true // } // }; var repositoryMock = new Mock <IMotorcycleRepository>(); // ACT (_, IError error) = ListMotorcyclesInteractor.NewListMotorcycleInteractor(repositoryMock.Object, null); // ASSERT Assert.NotNull(error); }