public async Task OrganisationByIdHandler_NotInternalUser_ThrowsSecurityException() { var authorization = AuthorizationBuilder.CreateFromUserType(AuthorizationBuilder.UserType.External); var handler = new OrganisationInternalByIdHandler(authorization, context, map); var message = new GetInternalOrganisation(Guid.NewGuid()); await Assert.ThrowsAsync <SecurityException>(async() => await handler.HandleAsync(message)); }
public async Task OrganisationByIdHandler_NoSuchOrganisation_ThrowsArgumentException() { var message = new GetInternalOrganisation(organisationId); A.CallTo(() => context.Organisations).Returns(dbHelper.GetAsyncEnabledDbSet(new List <Organisation>())); var exception = await Assert.ThrowsAsync <ArgumentException>(async() => await handler.HandleAsync(message)); Assert.True(exception.Message.Contains(organisationId.ToString())); Assert.True(exception.Message.ToUpperInvariant().Contains("COULD NOT FIND")); Assert.True(exception.Message.ToUpperInvariant().Contains("ORGANISATION")); }
public async Task OrganisationByIdHandler_GivenMappedOrganisation_MappedOrganisationShouldBeReturned() { var message = new GetInternalOrganisation(organisationId); var expectedReturnValue = new OrganisationData(); A.CallTo(() => map.Map(A <Organisation> ._)).Returns(expectedReturnValue); var result = await handler.HandleAsync(message); result.Should().Be(expectedReturnValue); }
public async Task OrganisationByIdHandler_ReturnsFalseForCanEditOrganisation_WhenCurrentUserIsNotInternalAdmin() { var weeeAuthorization = new AuthorizationBuilder() .AllowInternalAreaAccess() .DenyRole(Roles.InternalAdmin) .Build(); var handler = new OrganisationInternalByIdHandler(weeeAuthorization, context, map); var message = new GetInternalOrganisation(organisationId); var result = await handler.HandleAsync(message); result.CanEditOrganisation.Should().BeFalse(); }
public async Task OrganisationByIdHandler_HappyPath_ReturnsOrganisationFromId() { var authorization = AuthorizationBuilder.CreateUserWithAllRights(); var expectedReturnValue = new OrganisationData(); A.CallTo(() => map.Map(A <Organisation> ._)).Returns(expectedReturnValue); var message = new GetInternalOrganisation(organisationId); var result = await handler.HandleAsync(message); Assert.NotNull(expectedReturnValue); Assert.Same(expectedReturnValue, result); }