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);
        }
        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 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 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);
        }
        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());
        }