public void HttpAuthorizeAttribute_OnAuthorize_WithAuthorizedHeader_ReturnsAuthorization() { ConfigUtilityMock.Setup(x => x.ApiKey).Returns(ApiKey); var po = new PrivateObject(ClassUnderTest); var scheme = (string)po.GetField("Scheme", BindingFlags.NonPublic | BindingFlags.Static); var headerValue = new AuthenticationHeaderValue(scheme, ApiKey); var context = new HttpActionContext(); var request = new HttpRequestMessage(); var controllerContext = new HttpControllerContext(); request.Headers.Authorization = headerValue; controllerContext.Request = request; context.ControllerContext = controllerContext; context.Request.RequestUri = new Uri("http://test.com"); var isAuthorizedWasCalled = false; var expectedContext = new HttpActionContext(); ShimAuthorizeAttribute.AllInstances.IsAuthorizedHttpActionContext = (x, y) => { isAuthorizedWasCalled = true; expectedContext = y; return(true); }; ClassUnderTest.OnAuthorization(context); Assert.Null(context.Response); Assert.True(isAuthorizedWasCalled); Assert.Equal(expectedContext, context); }
public void PrepareEZLayout_KeyCategoryShortcuts(string keyCode, string command, string expectedLabel, KeyCategory expectedCategory) { // Arrange var ergodoxKey = new ErgodoxKey() { GlowColor = "", Code = keyCode, Command = command }; ErgodoxLayout ergodoxLayout = InitializeDataTree(); ergodoxLayout.Revision.Layers.First().Keys.Add(ergodoxKey); EZLayout ezLayoutResult; // Act var ezLayoutMaker = new EZLayoutMaker(); ezLayoutResult = ezLayoutMaker.PrepareEZLayout(ergodoxLayout); // Assert Assert.Single(ezLayoutResult.EZLayers); Assert.Single(ezLayoutResult.EZLayers.First().EZKeys); var keyResult = ezLayoutResult.EZLayers.First().EZKeys.First(); Assert.Equal(expectedLabel, keyResult.Label.Content); Assert.Null(keyResult.Modifier); Assert.Equal(expectedCategory, keyResult.KeyCategory); }
public void GetLatestProducerForComplianceYearAndScheme_PrnDoesNotMatch_ReturnsNull() { using (DatabaseWrapper database = new DatabaseWrapper()) { ModelHelper helper = new ModelHelper(database.Model); // Arrange Scheme scheme = helper.CreateScheme(); MemberUpload memberUpload = helper.CreateMemberUpload(scheme); memberUpload.ComplianceYear = 2016; memberUpload.IsSubmitted = true; Weee.Tests.Core.Model.ProducerSubmission producer = helper.CreateProducerAsCompany(memberUpload, "AAAAAAAA"); database.Model.SaveChanges(); ProducerQuerySet querySet = ProducerQuerySet(database.WeeeContext); // Act var result = querySet.GetLatestProducerForComplianceYearAndScheme("XXXXXXXX", "2016", scheme.OrganisationId); // Assert Assert.Null(result); } }
public void NullablePrimaryKeysCanUpdate() { var filename = ""; var accessor = CreateAccessor(out filename); var one = new NullableKeyTest() { A = 1, B = null, Value = "one" }; accessor.WriteEntity(one); one.Value = "two"; accessor.WriteEntity(one); var two = accessor.ReadEntities <NullableKeyTest>("SELECT * FROM [NullableKeyTest]") .Single(); Assert.Equal(1, two.A); Assert.Null(two.B); Assert.Equal("two", two.Value); DestroyAccessor(filename); }
public void UpdateHandlerReturnsNullTest() { #region Test Setup var metadataFake = new Faker <MetadataInfo>() .RuleFor(m => m.Title, f => f.Lorem.Sentence()) .RuleFor(m => m.Description, f => f.Lorem.Paragraph()); var mockDefinitionFake = new Faker <MockDefinition>() .RuleFor(m => m.Host, f => f.Internet.DomainName()) .RuleFor(m => m.Metadata, f => metadataFake.Generate()); var options = new MemoryCacheOptions(); var cache = new MemoryCache(options); var mockDefinitionUpdate = mockDefinitionFake.Generate(); var updateMockDefinitionCommand = new UpdateMockDefinitionByTitleCommand(mockDefinitionUpdate, ref TestUtils.databaseLock); #endregion var Target = new UpdateMockDefinitionHandler(cache, data); var Actual = Target.Handle(updateMockDefinitionCommand, CancellationToken.None).Result; Assert.Null(Actual); }
public void DeleteMockDefinitionHandlerFromListSuccessTest() { #region TestSetup var metadataFake = new Faker <MetadataInfo>() .RuleFor(m => m.Title, f => f.Lorem.Sentence()) .RuleFor(m => m.Description, f => f.Lorem.Paragraph()); var mockDefinitionFake = new Faker <MockDefinition>() .RuleFor(m => m.Host, f => f.Internet.DomainName()) .RuleFor(m => m.Metadata, f => metadataFake.Generate()); var options = new MemoryCacheOptions(); var cache = new MemoryCache(options); var mockDefinition = mockDefinitionFake.Generate(); cache.Set(mockDefinition.Metadata.Title, mockDefinition); var expected = mockDefinition.Metadata.Title; cache.Set(data.mockIds, new List <string>() { mockDefinition.Metadata.Title }); var deleteMockDefinitionCommand = new DeleteMockDefinitionByTitleCommand(mockDefinition.Metadata.Title, ref TestUtils.databaseLock); #endregion var Target = new DeleteMockDefinitionHandler(cache, data); Target.Handle(deleteMockDefinitionCommand, CancellationToken.None); cache.TryGetValue(mockDefinition.Metadata.Title, out var Actual); Assert.Null(Actual); }
public void GetNonExistant() { var p = _repository.GetPrompt(new CultureInfo(1053), new TypePromptKey(typeof(TestType).FullName, "FirstNameOrSomething")); Assert.Null(p); }
public void VarbinaryTest() { var filename = ""; var accessor = CreateAccessor(out filename); var gnu = new VarbinaryTest() { Value1 = GetBytes("This is a test") }; accessor.WriteEntity(gnu); var existing = accessor.ReadEntities <VarbinaryTest>("SELECT * FROM [VarbinaryTest]"); Assert.Equal(1, existing.Count()); var first = existing.First(); Assert.Null(first.Value2); Assert.Null(first.Value3); var value = GetString(first.Value1); Assert.Equal("This is a test", value); DestroyAccessor(filename); }
public async Task SearchWhenProductDoesntExist() { //Arrange var goods = new[] { new Good() { Price = 2.12m, Product = new Preparation() { Name = "_world_" } } }; var mok = new Mock <IStreinger>(); mok.Setup(m => m.Goods()) .ReturnsAsync(goods); var seachController = new preparation.Controllers.SearchController(mok.Object, null); //Actual var resp = await seachController.Search("_not_found"); //Assert var viewResult = Assert.IsType <ViewResult>(resp); var model = viewResult.ViewData.Model; Assert.Null(model); }
public static void IsNull(object obj, string message = null) { #if XUNIT XUnitAssert.Null(obj); #else NUnitAssert.IsNull(obj, message); #endif }
public void PrepareEZLayout_ProcessModifiers(bool leftAlt, bool leftCtrl, bool leftShift, bool leftWin, bool rightAlt, bool rightCtrl, bool rightShift, bool rightWin, string expectedSubLabel, KeyDisplayType expectedDisplayType) { // Arrange var modifiers = new ErgodoxModifiers { LeftAlt = leftAlt, LeftCtrl = leftCtrl, LeftShift = leftShift, LeftWin = leftWin, RightAlt = rightAlt, RightCtrl = rightCtrl, RightShift = rightShift, RightWin = rightWin }; var ergodoxKey = new ErgodoxKey() { GlowColor = "", Code = "KC_A", Modifiers = modifiers }; ErgodoxLayout ergodoxLayout = InitializeDataTree(); ergodoxLayout.Revision.Layers.First().Keys.Add(ergodoxKey); EZLayout ezLayoutResult; // Act var ezLayoutMaker = new EZLayoutMaker(); ezLayoutResult = ezLayoutMaker.PrepareEZLayout(ergodoxLayout); // Assert Assert.Single(ezLayoutResult.EZLayers); Assert.Single(ezLayoutResult.EZLayers.First().EZKeys); var keyResult = ezLayoutResult.EZLayers.First().EZKeys.First(); Assert.Equal("A", keyResult.Label.Content); if (expectedDisplayType == KeyDisplayType.SimpleLabel) { Assert.Null(keyResult.Modifier); } else { Assert.Equal(expectedSubLabel, keyResult.Modifier.Content); Assert.False(keyResult.Modifier.IsGlyph); } Assert.Equal(expectedDisplayType, keyResult.DisplayType); }
public void Update() { var key = new TypePromptKey(typeof(TestType).FullName, "FirstName"); _repository.Update(new CultureInfo(1053), key, "Förrenammne"); var prompt = _repository.GetPrompt(new CultureInfo(1053), key); Assert.Null(prompt); }
public async Task Given_Incorrect_Claims_Principle_Returns_Null() { var claims = Array.Empty <Claim>(); var principal = new ClaimsPrincipal(new ClaimsIdentity(claims, "Basic")); var result = await Controller.GetCurrentUser(principal); Assert.Null(result); }
public void BookingPurchaseTests() { var result = _findRoomsController.Bookings("tenantName", 1, 5, 100, 2, 1); var redirectToActionResult = Assert.IsType <ViewResult>(result.Result); Assert.Null(redirectToActionResult.ContentType); Assert.Equal("TenantError", redirectToActionResult.ViewName); }
public void LoginTest() { //Act var result = _accountController.Login("tenantName", "*****@*****.**"); // Assert var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result); Assert.Null(redirectToActionResult.ControllerName); }
public void AuthenticateInValidUser_ReturnsUser() { UserService userService = new UserService(_fixture.context, _mailOptions); if (userService.Authenticate("*****@*****.**", "pass1") != null) { User user = userService.Authenticate("*****@*****.**", "pass1").Result; Assert.Null(user); } }
public void ErrorStatus_404_Redirect_to_Error404() { const string status_code = "404"; var result = _controller.ErrorStatus(status_code); var redirect_to_action = Assert.IsType <RedirectToActionResult>(result); Assert.Null(redirect_to_action.ControllerName); Assert.Equal(nameof(HomeController.NotFound), redirect_to_action.ActionName); }
public void ArgsWithPredicate() { var dictionary = Mock.Of <DictionaryService>(); Mock.Get(dictionary).Setup( d => d.LookUp(It.Is <string>(s => s.Last() == 's'))).Returns("plural"); Assert.Equal("plural", dictionary.LookUp("smelts")); Assert.Null(dictionary.LookUp("smelt")); }
public void RegisterCustomerTest() { //Act var result = _accountController.Register("tenantName", GetCustomer()); // Assert var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result); Assert.Null(redirectToActionResult.ControllerName); }
public void InitSelectManyTest() { using (var p = new PipeLine(CancellationToken.None)) { var x = p.InitSelectMany(Enumerable.Range(0, 100), 10, 10, i => Enumerable.Repeat(i, 3)); Assert.NotNull(x); Assert.Null(x.Next); var s = p.Start(() => Assert.Equal(4950 * 3, x.Out.Sum())); Assert.Equal(PipeLine.PipeLineStatus.Completed, s); } }
public void InitTest() { using (var p = new PipeLine(CancellationToken.None)) { var x = p.Init(Enumerable.Range(0, 100), 10, 10, i => i); Assert.NotNull(x); Assert.Null(x.Next); var s = p.Start(() => { Assert.Equal(4950, x.Out.Sum()); }); Assert.Equal(PipeLine.PipeLineStatus.Completed, s); } }
public void DeleteMockDefinitionHandlerNotFoundTest() { #region TestSetup var options = new MemoryCacheOptions(); var cache = new MemoryCache(options); var faker = new Faker(); var deleteMockDefinitionCommand = new DeleteMockDefinitionByTitleCommand(faker.Random.AlphaNumeric(40), ref TestUtils.databaseLock); #endregion var Target = new DeleteMockDefinitionHandler(cache, data); var exception = Record.Exception(() => Target.Handle(deleteMockDefinitionCommand, CancellationToken.None).Result); Assert.Null(exception); }
public void ConfigurationObjectMustBeRemoved() { //Arrange var configObj = _databaseFixture.CreateConfigurationObject(); //Act _databaseFixture.DatabaseAdapter.WriteConfigurationObject(configObj); _databaseFixture.DatabaseAdapter.RemoveConfigurationObject(configObj.Name); var objectFromDB = _databaseFixture.DatabaseAdapter.GetConfigurationObject(configObj.Name); //Assert Assert.Null(objectFromDB); }
WhenInValidRoadIDIsPassedThan_ResultWillBeNull() { var repo = new Mock <IGetResponseFromWebApi>(); var id = "A233"; repo.Setup(b => b.GetStatusOfRoadFromApi(It.IsAny <string>())).Returns(Task.FromResult(GetInvalidResponse())); var service = new GetRoadStatusServices(repo.Object); var result = await service.GetStatusOfRoad(id); Assert.Null(result); }
private void ValidateNativeLibraryResolutions( string nativeLibraryPaths, string expectedResolvedFilePath, string lookupName, OS resolvesOnOSes) { using (HostPolicyMock.Mock_corehost_resolve_component_dependencies( 0, "", $"{nativeLibraryPaths}", "")) { AssemblyDependencyResolver resolver = new AssemblyDependencyResolver( Path.Combine(TestBasePath, _componentAssemblyPath)); string result = resolver.ResolveUnmanagedDllToPath(lookupName); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { if (resolvesOnOSes.HasFlag(OS.Windows)) { Assert.Equal(expectedResolvedFilePath, result); } else { Assert.Null(result); } } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { if (resolvesOnOSes.HasFlag(OS.OSX)) { Assert.Equal(expectedResolvedFilePath, result); } else { Assert.Null(result); } } else { if (resolvesOnOSes.HasFlag(OS.Linux)) { Assert.Equal(expectedResolvedFilePath, result); } else { Assert.Null(result); } } } }
public void RegisterTicketMustBeRemoved() { //Arrange var ticket = _databaseFixture.CreateRegistrationTicket(); //Act _databaseFixture.DatabaseAdapter.WriteRegistrationTicket(ticket); Thread.Sleep(1000); _databaseFixture.DatabaseAdapter.RemoveRegistrationTicket(ticket.Id); var ticketFromDB = _databaseFixture.DatabaseAdapter.ReadRegistrationTicket(ticket.Id); //Assert Assert.Null(ticketFromDB); }
public void ResponseSelectorFilterFaultedTest() { var port = new ProcessMessagePort() { Faults = new List <string> { "fault" } }; var Target = new ResponseSelectorFilter <ProcessMessagePort>(new TemplateContext()); var Actual = Target.Process(port).SelectedResponse; Assert.Null(Actual); }
public void GetByIdDepartmentNotFound() { // Arrange var config = new MapperConfiguration(cfg => cfg.CreateMap <Department, DepartmentDTO>()); var mock = new Mock <IUnitOfWork>(); mock.Setup(unitOfWork => unitOfWork.Departments.Get(3)).Returns(null as Department); var manager = new DepartmentManager(mock.Object, new AttributeValidator(), new Mapper(config)); // Act var result = manager.GetById(3); // Arrange Assert.Null(result); }
public void TestAssemblyWithMissingFile() { // Even if the .deps.json can resolve the request, if the file is not present // the resolution should still return null. using (HostPolicyMock.Mock_corehost_resolve_component_dependencies( 0, Path.Combine(_componentDirectory, "NonExistingAssembly.dll"), "", "")) { AssemblyDependencyResolver resolver = new AssemblyDependencyResolver( Path.Combine(TestBasePath, _componentAssemblyPath)); Assert.Null(resolver.ResolveAssemblyToPath(new AssemblyName("NonExistingAssembly"))); } }
public void TestAssemblyWithNoRecord() { // If the reqest is for assembly which is not listed in .deps.json // the resolver should return null. using (HostPolicyMock.Mock_corehost_resolve_component_dependencies( 0, "", "", "")) { AssemblyDependencyResolver resolver = new AssemblyDependencyResolver( Path.Combine(TestBasePath, _componentAssemblyPath)); Assert.Null(resolver.ResolveAssemblyToPath(new AssemblyName("AssemblyWithNoRecord"))); } }