Пример #1
0
            public async Task NonexistentNamespaceThrowsException()
            {
                var testNamespaces = ReservedNamespaceServiceTestData.GetTestNamespaces();
                var service        = new TestableReservedNamespaceService(reservedNamespaces: testNamespaces);

                await Assert.ThrowsAsync <InvalidOperationException>(async() => await service.DeleteReservedNamespaceAsync("Nonexistent.Namespace."));
            }
Пример #2
0
            public async Task DeleteOwnerFromNamespaceSuccessfully()
            {
                var testNamespaces    = ReservedNamespaceServiceTestData.GetTestNamespaces();
                var prefix            = "microsoft.";
                var existingNamespace = testNamespaces.FirstOrDefault(rn => rn.Value.Equals(prefix, StringComparison.OrdinalIgnoreCase));
                var testUsers         = ReservedNamespaceServiceTestData.GetTestUsers();
                var owner             = testUsers.First();

                existingNamespace.Owners.Add(owner);
                var service = new TestableReservedNamespaceService(reservedNamespaces: testNamespaces, users: testUsers);

                await service.DeleteOwnerFromReservedNamespaceAsync(prefix, owner.Username);

                service
                .MockReservedNamespaceRepository
                .Verify(x => x.CommitChangesAsync());

                service
                .MockPackageService
                .Verify(p => p.UpdatePackageVerifiedStatusAsync(
                            It.IsAny <IReadOnlyCollection <PackageRegistration> >(), It.IsAny <bool>()),
                        Times.Never);

                Assert.False(existingNamespace.Owners.Contains(owner));
            }
            public async Task WillMarkPackageRegistrationVerifiedFlagCorrectly(bool shouldMarkIdVerified)
            {
                var id             = "Microsoft.Aspnet.Mvc";
                var testNamespaces = ReservedNamespaceServiceTestData.GetTestNamespaces();
                var prefixes       = new List <string> {
                    "microsoft.", "microsoft.aspnet."
                };
                var testUsers          = ReservedNamespaceServiceTestData.GetTestUsers();
                var firstUser          = testUsers.First();
                var matchingNamepsaces = testNamespaces
                                         .Where(rn => prefixes.Any(pr => id.StartsWith(pr, StringComparison.OrdinalIgnoreCase)))
                                         .ToList();

                prefixes.ForEach(p => {
                    var existingNamespace = testNamespaces.FirstOrDefault(rn => rn.Value.Equals(p, StringComparison.OrdinalIgnoreCase));
                    existingNamespace.Owners.Add(firstUser);
                });

                var reservedNamespaceService = new Mock <IReservedNamespaceService>();
                IReadOnlyCollection <ReservedNamespace> userOwnedMatchingNamespaces = matchingNamepsaces;

                reservedNamespaceService.Setup(s => s.IsPushAllowed(It.IsAny <string>(), It.IsAny <User>(), out userOwnedMatchingNamespaces))
                .Returns(shouldMarkIdVerified);

                var packageUploadService = CreateService(reservedNamespaceService: reservedNamespaceService);
                var nugetPackage         = PackageServiceUtility.CreateNuGetPackage(id: id);

                var package = await packageUploadService.GeneratePackageAsync(id, nugetPackage.Object, new PackageStreamMetadata(), firstUser);

                Assert.Equal(shouldMarkIdVerified, package.PackageRegistration.IsVerified);
            }
            public async Task WillMarkPackageRegistrationNotVerifiedIfIdMatchesNonOwnedSharedNamespace()
            {
                var id             = "Microsoft.Aspnet.Mvc";
                var testNamespaces = ReservedNamespaceServiceTestData.GetTestNamespaces();
                var prefixes       = new List <string> {
                    "microsoft.", "microsoft.aspnet."
                };
                var testUsers = ReservedNamespaceServiceTestData.GetTestUsers();
                var firstUser = testUsers.First();
                var lastUser  = testUsers.Last();

                prefixes.ForEach(p => {
                    var existingNamespace = testNamespaces.FirstOrDefault(rn => rn.Value.Equals(p, StringComparison.OrdinalIgnoreCase));
                    existingNamespace.IsSharedNamespace = true;
                    existingNamespace.Owners.Add(firstUser);
                });

                var reservedNamespaceService = new Mock <IReservedNamespaceService>();
                IReadOnlyCollection <ReservedNamespace> userOwnedMatchingNamespaces = new List <ReservedNamespace>();

                reservedNamespaceService.Setup(s => s.IsPushAllowed(It.IsAny <string>(), It.IsAny <User>(), out userOwnedMatchingNamespaces))
                .Returns(true);

                var packageUploadService = CreateService(reservedNamespaceService: reservedNamespaceService);
                var nugetPackage         = PackageServiceUtility.CreateNuGetPackage(id: id);

                var package = await packageUploadService.GeneratePackageAsync(id, nugetPackage.Object, new PackageStreamMetadata(), lastUser);

                Assert.False(package.PackageRegistration.IsVerified);
            }
Пример #5
0
            public async Task ExistingNamespaceThrowsException()
            {
                var testNamespaces = ReservedNamespaceServiceTestData.GetTestNamespaces();
                var newNamespace   = testNamespaces.FirstOrDefault();
                var service        = new TestableReservedNamespaceService(reservedNamespaces: testNamespaces);

                await Assert.ThrowsAsync <InvalidOperationException>(async() => await service.AddReservedNamespaceAsync(newNamespace));
            }
Пример #6
0
            public async Task DeletingInvalidOwnerFromNamespaceThrowsException(string username)
            {
                var testNamespaces    = ReservedNamespaceServiceTestData.GetTestNamespaces();
                var existingNamespace = testNamespaces.First();
                var service           = new TestableReservedNamespaceService(reservedNamespaces: testNamespaces);

                await Assert.ThrowsAsync <ArgumentException>(async() => await service.DeleteOwnerFromReservedNamespaceAsync(existingNamespace.Value, username));
            }
Пример #7
0
            public async Task NonExistentNamespaceThrowsException()
            {
                var testNamespaces = ReservedNamespaceServiceTestData.GetTestNamespaces();
                var testUsers      = ReservedNamespaceServiceTestData.GetTestUsers();
                var existingUser   = testUsers.First();
                var service        = new TestableReservedNamespaceService(reservedNamespaces: testNamespaces, users: testUsers);

                await Assert.ThrowsAsync <InvalidOperationException>(async() => await service.DeleteOwnerFromReservedNamespaceAsync("Non.Existent.Namespace.", existingUser.Username));
            }
Пример #8
0
            public async Task DeletingNonExistentUserFromNamespaceThrowsException()
            {
                var testNamespaces    = ReservedNamespaceServiceTestData.GetTestNamespaces();
                var existingNamespace = testNamespaces.First();
                var testUsers         = ReservedNamespaceServiceTestData.GetTestUsers();
                var service           = new TestableReservedNamespaceService(reservedNamespaces: testNamespaces, users: testUsers);

                await Assert.ThrowsAsync <InvalidOperationException>(async() => await service.DeleteOwnerFromReservedNamespaceAsync(existingNamespace.Value, "NonExistentUser"));
            }
Пример #9
0
            public async Task NonExistentNamespaceThrowsException()
            {
                var testNamespaces           = ReservedNamespaceServiceTestData.GetTestNamespaces();
                var testPackageRegistrations = ReservedNamespaceServiceTestData.GetRegistrations();
                var existingReg = testPackageRegistrations.First();
                var service     = new TestableReservedNamespaceService(reservedNamespaces: testNamespaces, packageRegistrations: testPackageRegistrations);

                await Assert.ThrowsAsync <InvalidOperationException>(async() => await service.AddPackageRegistrationToNamespaceAsync("Non.Existent.Namespace.", existingReg));
            }
Пример #10
0
            public async Task LiberalNamespaceThrowsException()
            {
                var testNamespaces = ReservedNamespaceServiceTestData.GetTestNamespaces();
                // test case has a namespace with "Microsoft." as the value.
                var newNamespace = new ReservedNamespace("Micro", isSharedNamespace: false, isPrefix: true);
                var service      = new TestableReservedNamespaceService(reservedNamespaces: testNamespaces);

                await Assert.ThrowsAsync <InvalidOperationException>(async() => await service.AddReservedNamespaceAsync(newNamespace));
            }
            public void NonExistentNamespaceThrowsException()
            {
                var testNamespaces           = ReservedNamespaceServiceTestData.GetTestNamespaces();
                var testPackageRegistrations = ReservedNamespaceServiceTestData.GetRegistrations();
                var existingReg = testPackageRegistrations.First();
                var service     = new TestableReservedNamespaceService(reservedNamespaces: testNamespaces, packageRegistrations: testPackageRegistrations);

                Assert.Throws <InvalidOperationException>(() => service.RemovePackageRegistrationFromNamespace("Non.Existent.Namespace.", existingReg));
            }
Пример #12
0
            public async Task ExistingNamespaceWithDifferentPrefixStateThrowsException()
            {
                var testNamespaces = ReservedNamespaceServiceTestData.GetTestNamespaces();
                var newNamespace   = testNamespaces.FirstOrDefault(x => x.Value == "jquery");

                newNamespace.IsPrefix = !newNamespace.IsPrefix;
                var service = new TestableReservedNamespaceService(reservedNamespaces: testNamespaces);

                await Assert.ThrowsAsync <InvalidOperationException>(async() => await service.AddReservedNamespaceAsync(newNamespace));
            }
            public async Task AddingOwnerToAbsoluteNamespaceMarksOnlyAbsoluteRegistrationsVerified()
            {
                var testNamespaces    = ReservedNamespaceServiceTestData.GetTestNamespaces();
                var existingNamespace = new ReservedNamespace("Microsoft", isSharedNamespace: false, isPrefix: false);

                testNamespaces.Add(existingNamespace);
                var testUsers     = ReservedNamespaceServiceTestData.GetTestUsers();
                var owner1        = testUsers.First(u => u.Username == "test1");
                var registrations = ReservedNamespaceServiceTestData.GetRegistrations();
                var pr1           = registrations.ToList().FirstOrDefault(pr => (pr.Id == "Microsoft.Package1"));
                var pr2           = registrations.ToList().FirstOrDefault(pr => (pr.Id == "Microsoft.Package2"));
                var pr3           = registrations.ToList().FirstOrDefault(pr => (pr.Id == "Microsoft.AspNet.Package2"));
                var pr4           = new PackageRegistration {
                    Id = "Microsoft", IsVerified = false
                };

                registrations.Add(pr4);

                pr1.Owners.Add(owner1);
                pr2.Owners.Add(owner1);
                pr3.Owners.Add(owner1);
                pr4.Owners.Add(owner1);

                var service = new TestableReservedNamespaceService(reservedNamespaces: testNamespaces, users: testUsers, packageRegistrations: registrations);

                Assert.True(existingNamespace.PackageRegistrations.Count() == 0);

                await service.AddOwnerToReservedNamespaceAsync(existingNamespace.Value, owner1.Username);

                service
                .MockReservedNamespaceRepository
                .Verify(x => x.CommitChangesAsync());

                service
                .MockPackageService
                .Verify(p => p.UpdatePackageVerifiedStatusAsync(
                            It.IsAny <IReadOnlyCollection <PackageRegistration> >(), It.IsAny <bool>()),
                        Times.Once);

                Assert.True(existingNamespace.Owners.Contains(owner1));
                // Only Microsoft.Package1 should match the namespace
                Assert.True(existingNamespace.PackageRegistrations.Count() == 1);
                existingNamespace
                .PackageRegistrations
                .ToList()
                .ForEach(pr =>
                {
                    Assert.True(pr.IsVerified);
                    Assert.True(pr.Id == pr4.Id);
                });
                Assert.False(pr1.IsVerified);
                Assert.False(pr3.IsVerified);
                Assert.False(pr2.IsVerified);
            }
            public void PackageRegistrationIsAddedSuccessfully()
            {
                var testNamespaces           = ReservedNamespaceServiceTestData.GetTestNamespaces();
                var existingNamespace        = testNamespaces.First();
                var testPackageRegistrations = ReservedNamespaceServiceTestData.GetRegistrations();
                var existingReg = testPackageRegistrations.First();
                var service     = new TestableReservedNamespaceService(reservedNamespaces: testNamespaces, packageRegistrations: testPackageRegistrations);

                service.AddPackageRegistrationToNamespace(existingNamespace.Value, existingReg);

                Assert.True(existingNamespace.PackageRegistrations.Contains(existingReg));
            }
Пример #15
0
            public async Task AddingExistingOwnerToTheNamespaceThrowsException()
            {
                var testNamespaces    = ReservedNamespaceServiceTestData.GetTestNamespaces();
                var prefix            = "microsoft.";
                var existingNamespace = testNamespaces.FirstOrDefault(rn => rn.Value.Equals(prefix, StringComparison.OrdinalIgnoreCase));
                var testUsers         = ReservedNamespaceServiceTestData.GetTestUsers();
                var owner             = testUsers.First();

                existingNamespace.Owners.Add(owner);
                var service = new TestableReservedNamespaceService(reservedNamespaces: testNamespaces, users: testUsers);

                await Assert.ThrowsAsync <InvalidOperationException>(async() => await service.AddOwnerToReservedNamespaceAsync(existingNamespace.Value, owner.Username));
            }
Пример #16
0
            public async Task DeletingNonOwnerFromNamespaceThrowsException()
            {
                var testNamespaces    = ReservedNamespaceServiceTestData.GetTestNamespaces();
                var prefix            = "microsoft.";
                var existingNamespace = testNamespaces.FirstOrDefault(rn => rn.Value.Equals(prefix, StringComparison.OrdinalIgnoreCase));
                var testUsers         = ReservedNamespaceServiceTestData.GetTestUsers();
                var user1             = testUsers.First(u => u.Username == "test1");
                var user2             = testUsers.First(u => u.Username == "test2");

                existingNamespace.Owners.Add(user1);
                var service = new TestableReservedNamespaceService(reservedNamespaces: testNamespaces, users: testUsers);

                await Assert.ThrowsAsync <InvalidOperationException>(async() => await service.DeleteOwnerFromReservedNamespaceAsync(prefix, user2.Username));
            }
            public void PackageRegistrationIsRemovedFromNamespaceSuccessfully()
            {
                var testNamespaces           = ReservedNamespaceServiceTestData.GetTestNamespaces();
                var existingNamespace        = testNamespaces.First();
                var testPackageRegistrations = ReservedNamespaceServiceTestData.GetRegistrations();
                var existingReg = testPackageRegistrations.First();

                existingNamespace.PackageRegistrations.Add(existingReg);
                var service = new TestableReservedNamespaceService(reservedNamespaces: testNamespaces, packageRegistrations: testPackageRegistrations);

                service.RemovePackageRegistrationFromNamespace(existingNamespace.Value, existingReg);

                Assert.False(existingNamespace.PackageRegistrations.Contains(existingReg));
            }
            public void CommitChangesIsNotExecuted()
            {
                var testNamespaces           = ReservedNamespaceServiceTestData.GetTestNamespaces();
                var existingNamespace        = testNamespaces.First();
                var testPackageRegistrations = ReservedNamespaceServiceTestData.GetRegistrations();
                var existingReg = testPackageRegistrations.First();
                var service     = new TestableReservedNamespaceService(reservedNamespaces: testNamespaces, packageRegistrations: testPackageRegistrations);

                service.AddPackageRegistrationToNamespace(existingNamespace.Value, existingReg);

                service
                .MockReservedNamespaceRepository
                .Verify(x => x.CommitChangesAsync(), Times.Never);
            }
        public async void RemoveNamespaceSuccesfullyDeletesNamespace(string value)
        {
            // Arrange.
            var namespaces               = ReservedNamespaceServiceTestData.GetTestNamespaces();
            var existingNamespace        = namespaces.Where(rn => rn.Value.Equals(value, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
            var reservedNamespaceService = new TestableReservedNamespaceService(reservedNamespaces: namespaces);
            var controller               = new ReservedNamespaceController(reservedNamespaceService);

            // Act & Assert.
            JsonResult result = await controller.RemoveNamespace(existingNamespace);

            dynamic data = result.Data;

            Assert.True(data.success);
        }
        public async void AddNamespaceSuccessfullyAddsNewNamespaces(string value, bool isSharedNamespace, bool isPrefix)
        {
            // Arrange.
            var namespaces               = ReservedNamespaceServiceTestData.GetTestNamespaces();
            var newNamespace             = new ReservedNamespace(value, isSharedNamespace, isPrefix);
            var reservedNamespaceService = new TestableReservedNamespaceService(reservedNamespaces: namespaces);
            var controller               = new ReservedNamespaceController(reservedNamespaceService);

            // Act & Assert.
            JsonResult result = await controller.AddNamespace(newNamespace);

            dynamic data = result.Data;

            Assert.True(data.success);
        }
Пример #21
0
            public async Task PackageRegistrationIsAddedWithCommitSuccessfully()
            {
                var testNamespaces           = ReservedNamespaceServiceTestData.GetTestNamespaces();
                var existingNamespace        = testNamespaces.First();
                var testPackageRegistrations = ReservedNamespaceServiceTestData.GetRegistrations();
                var existingReg = testPackageRegistrations.First();
                var service     = new TestableReservedNamespaceService(reservedNamespaces: testNamespaces, packageRegistrations: testPackageRegistrations);

                await service.AddPackageRegistrationToNamespaceAsync(existingNamespace.Value, existingReg, commitChanges : true);

                service
                .MockReservedNamespaceRepository
                .Verify(x => x.CommitChangesAsync());
                Assert.True(existingNamespace.PackageRegistrations.Contains(existingReg));
            }
Пример #22
0
            public async Task CommitChangesIsNotExecuted()
            {
                var testNamespaces           = ReservedNamespaceServiceTestData.GetTestNamespaces();
                var existingNamespace        = testNamespaces.First();
                var testPackageRegistrations = ReservedNamespaceServiceTestData.GetRegistrations();
                var existingReg = testPackageRegistrations.First();
                var service     = new TestableReservedNamespaceService(reservedNamespaces: testNamespaces, packageRegistrations: testPackageRegistrations);

                await service.AddPackageRegistrationToNamespaceAsync(existingNamespace.Value, existingReg, commitChanges : false);

                service
                .MockReservedNamespaceRepository
                .Verify(x => x.CommitChangesAsync(), Times.Never);
                Assert.True(existingNamespace.PackageRegistrations.Contains(existingReg));
            }
        public async void AddNamespaceDoesNotReturnSuccessForInvalidNamespaces()
        {
            // Arrange.
            var namespaces               = ReservedNamespaceServiceTestData.GetTestNamespaces();
            var newNamespace             = namespaces.First();
            var reservedNamespaceService = new TestableReservedNamespaceService(reservedNamespaces: namespaces);
            var controller               = new ReservedNamespaceController(reservedNamespaceService);

            // Act & Assert.
            JsonResult result = await controller.AddNamespace(newNamespace);

            dynamic data = result.Data;

            Assert.False(data.success);
        }
        public async void AddOwnerSuccessfullyAddsOwnerToReservedNamespace(string value, string username)
        {
            // Arrange.
            var namespaces               = ReservedNamespaceServiceTestData.GetTestNamespaces();
            var allUsers                 = ReservedNamespaceServiceTestData.GetTestUsers();
            var existingNamespace        = namespaces.Where(rn => rn.Value.Equals(value, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
            var reservedNamespaceService = new TestableReservedNamespaceService(reservedNamespaces: namespaces, users: allUsers);
            var controller               = new ReservedNamespaceController(reservedNamespaceService);

            // Act & Assert.
            JsonResult result = await controller.AddOwner(existingNamespace, username);

            dynamic data = result.Data;

            Assert.True(data.success);
        }
        public async void RemoveNamespaceDoesNotReturnSuccessForInvalidNamespaces(string value)
        {
            // Arrange.
            var namespaces       = ReservedNamespaceServiceTestData.GetTestNamespaces();
            var invalidNamespace = new ReservedNamespace();

            invalidNamespace.Value = value;
            var reservedNamespaceService = new TestableReservedNamespaceService(reservedNamespaces: namespaces);
            var controller = new ReservedNamespaceController(reservedNamespaceService);

            // Act & Assert.
            JsonResult result = await controller.RemoveNamespace(invalidNamespace);

            dynamic data = result.Data;

            Assert.False(data.success);
        }
Пример #26
0
            public void OwnedNamespacesAllowsPush(string id)
            {
                var testNamespaces    = ReservedNamespaceServiceTestData.GetTestNamespaces();
                var prefix            = "microsoft.";
                var existingNamespace = testNamespaces.FirstOrDefault(rn => rn.Value.Equals(prefix, StringComparison.OrdinalIgnoreCase));
                var testUsers         = ReservedNamespaceServiceTestData.GetTestUsers();
                var firstUser         = testUsers.First();

                existingNamespace.Owners.Add(firstUser);
                var service = new TestableReservedNamespaceService(reservedNamespaces: testNamespaces, users: testUsers);

                var isPushAllowed = service.IsPushAllowed(id, firstUser, out IReadOnlyCollection <ReservedNamespace> matchingNamespaces);

                Assert.True(isPushAllowed);
                Assert.NotEmpty(matchingNamespaces);
                Assert.True(matchingNamespaces.Count() == 1);
            }
Пример #27
0
            public async Task DeletingOwnerFromNamespaceMarksRegistrationsUnverified()
            {
                var testNamespaces    = ReservedNamespaceServiceTestData.GetTestNamespaces();
                var prefix            = "microsoft.";
                var existingNamespace = testNamespaces.FirstOrDefault(rn => rn.Value.Equals(prefix, StringComparison.OrdinalIgnoreCase));
                var testUsers         = ReservedNamespaceServiceTestData.GetTestUsers();
                var owner1            = testUsers.First(u => u.Username == "test1");
                var owner2            = testUsers.First(u => u.Username == "test2");
                var registrations     = ReservedNamespaceServiceTestData.GetRegistrations();
                var pr1 = registrations.ToList().FirstOrDefault(pr => (pr.Id == "Microsoft.Package1"));
                var pr2 = registrations.ToList().FirstOrDefault(pr => (pr.Id == "Microsoft.Package2"));
                var pr3 = registrations.ToList().FirstOrDefault(pr => (pr.Id == "Microsoft.AspNet.Package2"));

                pr1.Owners.Add(owner1);
                pr2.Owners.Add(owner1);
                pr3.Owners.Add(owner2);
                pr1.IsVerified = true;
                pr2.IsVerified = true;
                pr3.IsVerified = true;
                existingNamespace.Owners.Add(owner1);
                existingNamespace.PackageRegistrations.Add(pr1);
                existingNamespace.PackageRegistrations.Add(pr2);

                var service = new TestableReservedNamespaceService(reservedNamespaces: testNamespaces, users: testUsers, packageRegistrations: registrations);

                Assert.True(existingNamespace.PackageRegistrations.Count == 2);

                await service.DeleteOwnerFromReservedNamespaceAsync(prefix, owner1.Username);

                service
                .MockReservedNamespaceRepository
                .Verify(x => x.CommitChangesAsync());

                service
                .MockPackageService
                .Verify(p => p.UpdatePackageVerifiedStatusAsync(
                            It.IsAny <IReadOnlyCollection <PackageRegistration> >(), It.IsAny <bool>()),
                        Times.Once);

                Assert.False(existingNamespace.Owners.Contains(owner1));
                Assert.True(existingNamespace.PackageRegistrations.Count == 0);
                Assert.False(pr1.IsVerified);
                Assert.False(pr2.IsVerified);
                Assert.True(pr3.IsVerified);
            }
Пример #28
0
            public async Task LiberalNamespaceForExactMatchIsAllowed()
            {
                var testNamespaces = ReservedNamespaceServiceTestData.GetTestNamespaces();
                // test case has a namespace with "Microsoft." as the value.
                var newNamespace = new ReservedNamespace("Micro", isSharedNamespace: false, isPrefix: false /*exact match*/);
                var service      = new TestableReservedNamespaceService(reservedNamespaces: testNamespaces);

                await service.AddReservedNamespaceAsync(newNamespace);

                service.MockReservedNamespaceRepository.Verify(
                    x => x.InsertOnCommit(
                        It.Is <ReservedNamespace>(
                            rn => rn.Value == newNamespace.Value &&
                            rn.IsPrefix == newNamespace.IsPrefix &&
                            rn.IsSharedNamespace == newNamespace.IsSharedNamespace)));

                service.MockReservedNamespaceRepository.Verify(x => x.CommitChangesAsync());
            }
        public async void RemoveOwnerDoesNotReturnSuccessForInvalidData(string value, string username)
        {
            // Arrange.
            var namespaces        = ReservedNamespaceServiceTestData.GetTestNamespaces();
            var allUsers          = ReservedNamespaceServiceTestData.GetTestUsers();
            var existingNamespace = namespaces.Where(rn => rn.Value.Equals(value, StringComparison.OrdinalIgnoreCase)).FirstOrDefault() ?? new ReservedNamespace();

            existingNamespace.Value = value;
            var reservedNamespaceService = new TestableReservedNamespaceService(reservedNamespaces: namespaces, users: allUsers);
            var controller = new ReservedNamespaceController(reservedNamespaceService);

            // Act & Assert.
            JsonResult result = await controller.RemoveOwner(existingNamespace, username);

            dynamic data = result.Data;

            Assert.False(data.success);
        }
        public void SearchFindsMatchingPrefixes(string query, int foundCount, int notFoundCount)
        {
            // Arrange.
            var namespaces = ReservedNamespaceServiceTestData.GetTestNamespaces();
            var reservedNamespaceService = new TestableReservedNamespaceService(reservedNamespaces: namespaces);
            var controller = new ReservedNamespaceController(reservedNamespaceService);

            // Act.
            JsonResult jsonResult = controller.SearchPrefix(query);

            // Assert
            dynamic data            = jsonResult.Data;
            var     resultModelList = data.Prefixes as IEnumerable <ReservedNamespaceResultModel>;
            var     found           = resultModelList.Where(r => r.isExisting);
            var     notFound        = resultModelList.Where(r => !r.isExisting);

            Assert.Equal(foundCount, found.Count());
            Assert.Equal(notFoundCount, notFound.Count());
        }