Example #1
0
            public async Task WhenOrganizationIsNull_ThrowsException()
            {
                // Arrange
                var service = new TestableUserService();

                // Act & Assert
                await Assert.ThrowsAsync <ArgumentNullException>(async() =>
                {
                    await service.UpdateMemberAsync(null, "member", false);
                });
            }
Example #2
0
            public async Task WhenMemberNotFound_ThrowsEntityException()
            {
                // Arrange
                var fakes   = new Fakes();
                var service = new TestableUserService();

                // Act & Assert
                await Assert.ThrowsAsync <EntityException>(async() =>
                {
                    await service.UpdateMemberAsync(fakes.Organization, fakes.User.Username, false);
                });

                service.MockEntitiesContext.Verify(c => c.SaveChangesAsync(), Times.Never);
            }
Example #3
0
            public async Task WhenRemovingLastAdmin_ThrowsEntityException()
            {
                // Arrange
                var fakes   = new Fakes();
                var service = new TestableUserService();

                // Act & Assert
                var exception = await Assert.ThrowsAsync <EntityException>(async() =>
                {
                    await service.UpdateMemberAsync(fakes.Organization, fakes.OrganizationAdmin.Username, false);
                });

                service.MockEntitiesContext.Verify(c => c.SaveChangesAsync(), Times.Never);
                Assert.Equal(
                    Strings.UpdateMember_CannotRemoveLastAdmin,
                    exception.Message);
            }
Example #4
0
            public async Task WhenNotRemovingLastAdmin_ReturnsSuccess()
            {
                // Arrange
                var fakes   = new Fakes();
                var service = new TestableUserService();

                foreach (var m in fakes.Organization.Members)
                {
                    m.IsAdmin = true;
                }

                // Act
                var result = await service.UpdateMemberAsync(fakes.Organization, fakes.OrganizationAdmin.Username, false);

                // Assert
                Assert.Equal(false, result.IsAdmin);
                Assert.Equal(fakes.OrganizationAdmin, result.Member);

                service.MockEntitiesContext.Verify(c => c.SaveChangesAsync(), Times.Once);
            }