public void TestGetActionMultipleChoicesDefault() { INakedObject choicesRepo = NakedObjectsFramework.GetAdaptedService("ChoicesRepository"); const string actionName = "AnActionMultiple"; string id = NakedObjectsFramework.GetObjectId(choicesRepo); const string parm1Id = "ChoicesRepository-AnActionMultiple-Parm1-Select0"; const string parm2Id = "ChoicesRepository-AnActionMultiple-Parm2-Select0"; const string parm3Id = "ChoicesRepository-AnActionMultiple-Parm3-Select0"; mocks.Request.Setup(x => x.Params).Returns(new NameValueCollection { { parm1Id, "" }, { parm2Id, "" }, { parm3Id, "" }, }); JsonResult result = controller.GetActionChoices(id, actionName); Assert.IsInstanceOf <IDictionary <string, string[][]> >(result.Data); var dict = result.Data as IDictionary <string, string[][]>; Assert.AreEqual(2, dict.Count); Assert.IsTrue(dict.ContainsKey("ChoicesRepository-AnActionMultiple-Parm1-Select")); Assert.IsTrue(dict.ContainsKey("ChoicesRepository-AnActionMultiple-Parm2-Select")); Assert.IsTrue(dict["ChoicesRepository-AnActionMultiple-Parm1-Select"][0].SequenceEqual(new[] { "value1", "value2" })); Assert.IsTrue(dict["ChoicesRepository-AnActionMultiple-Parm2-Select"][0].SequenceEqual(new string[] {})); Assert.IsTrue(dict["ChoicesRepository-AnActionMultiple-Parm1-Select"][1].SequenceEqual(new[] { "value1", "value2" })); Assert.IsTrue(dict["ChoicesRepository-AnActionMultiple-Parm2-Select"][1].SequenceEqual(new string[] {})); }
public void TestGetPropertyChoicesOtherValue() { INakedObject choicesRepo = NakedObjectsFramework.GetAdaptedService("ChoicesRepository"); object choicesObject = choicesRepo.GetDomainObject <ChoicesRepository>().GetChoicesObject(); string id = NakedObjectsFramework.GetObjectId(choicesObject); const string parm1Id = "ChoicesObject-Name-Input0"; const string parm2Id = "ChoicesObject-AProperty-Input0"; mocks.Request.Setup(x => x.Params).Returns(new NameValueCollection { { parm1Id, "AName" }, { parm2Id, "" } }); JsonResult result = controller.GetPropertyChoices(id); Assert.IsInstanceOf <IDictionary <string, string[][]> >(result.Data); var dict = result.Data as IDictionary <string, string[][]>; Assert.AreEqual(1, dict.Count); Assert.IsTrue(dict.ContainsKey("ChoicesObject-AProperty-Input")); Assert.IsTrue(dict["ChoicesObject-AProperty-Input"][0].SequenceEqual(new[] { "AName-A", "AName-B" })); Assert.IsTrue(dict["ChoicesObject-AProperty-Input"][1].SequenceEqual(new[] { "AName-A", "AName-B" })); }
public void Is_Correct_RefreshToken_Mapped_Object() { //arrange var refreshToken = new RefreshToken { Id = "1234", ProtectedTicket = "1234", ClientId = "1234", ExpiresUtc = DateTime.Today.AddDays(1), IssuedUtc = DateTime.Today, Subject = "michal" }; var refreshTokenDto = new RefreshTokenDto { Id = "1234", ProtectedTicket = "1234", ClientId = "1234", ExpiresUtc = DateTime.Today.AddDays(1), IssuedUtc = DateTime.Today, Subject = "michal" }; var domainFactory = new RefreshTokenFactory(); //act var target = domainFactory.GetModel <RefreshToken>(refreshTokenDto); //assert Assert.IsInstanceOf <RefreshToken>(target); Assert.AreEqual(refreshToken.ProtectedTicket, target.ProtectedTicket); }
public void TestGetActionChoicesConditionalFailParse() { INakedObjectAdapter choicesRepo = NakedObjectsFramework.GetAdaptedService("ChoicesRepository"); const string actionName = "AnActionConditionalChoices"; string id = NakedObjectsFramework.GetObjectId(choicesRepo); const string parm1Id = "ChoicesRepository-AnActionConditionalChoices-Parm1-Input0"; const string parm2Id = "ChoicesRepository-AnActionConditionalChoices-Parm2-Input0"; const string parm3Id = "ChoicesRepository-AnActionConditionalChoices-Parm3-Input0"; mocks.Request.Setup(x => x.Params).Returns(new NameValueCollection { { parm1Id, "Fred" }, { parm2Id, "1" }, { parm3Id, "cannotparseasdate" } }); JsonResult result = controller.GetActionChoices(id, actionName); Assert.IsInstanceOf <IDictionary <string, string[][]> >(result.Data); var dict = result.Data as IDictionary <string, string[][]>; Assert.AreEqual(1, dict.Count); Assert.IsTrue(dict.ContainsKey("ChoicesRepository-AnActionConditionalChoices-Parm1-Input")); Assert.IsTrue(dict["ChoicesRepository-AnActionConditionalChoices-Parm1-Input"][0].SequenceEqual(new[] { "value1", "value2" })); Assert.IsTrue(dict["ChoicesRepository-AnActionConditionalChoices-Parm1-Input"][1].SequenceEqual(new[] { "value1", "value2" })); }
public async Task RegisterHttpPostEmailIsInUseTest() { var mockIUserStore = new Mock <IUserStore <User> >(); var mockIAuthenticationManager = new Mock <IAuthenticationManager>(); var mockApplicationUserManager = new Mock <ApplicationUserManager>(mockIUserStore.Object); mockApplicationUserManager.Setup(x => x.FindByEmailAsync(It.IsAny <string>())) .ReturnsAsync(new User()); var mockApplicationSignInManager = new Mock <ApplicationSignInManager>(mockApplicationUserManager.Object, mockIAuthenticationManager.Object); _accountController = new AccountController(mockApplicationUserManager.Object, mockApplicationSignInManager.Object, mockIAuthenticationManager.Object); var viewModel = new AccountRegisterViewModel() { Email = "email", Password = "******", ConfirmPassword = "******" }; var result = await _accountController.Register(viewModel); Assert.IsInstanceOf <ViewResult>(result); }
public void Is_Correct_Client_Mapped_Object() { //arrange var client = new Client { Active = true, RefreshTokenLifeTime = 1000, ApplicationType = 0, ClientSecret = "1234567890", Id = "1234", Username = "******" }; var clientDto = new ClientDto { Active = true, RefreshTokenLifeTime = 1000, ApplicationType = 0, ClientSecret = "1234567890", Id = "1234", Username = "******" }; var domainFactory = new ClientFactory(); //act var target = domainFactory.GetModel <Client>(clientDto); //assert Assert.IsInstanceOf <Client>(target); Assert.AreEqual(client.RefreshTokenLifeTime, target.RefreshTokenLifeTime); }
public async Task RegisterHttpPostSignInUserReturnsFailureTest() { var mockIUserStore = new Mock <IUserStore <User> >(); var mockIAuthenticationManager = new Mock <IAuthenticationManager>(); var mockApplicationUserManager = new Mock <ApplicationUserManager>(mockIUserStore.Object); mockApplicationUserManager.Setup(x => x.FindByEmailAsync(It.IsAny <string>())) .ReturnsAsync(default(User)); mockApplicationUserManager.Setup(x => x.CreateAsync(It.IsAny <User>(), It.IsAny <string>())) .ReturnsAsync(IdentityResult.Success); var mockApplicationSignInManager = new Mock <ApplicationSignInManager>(mockApplicationUserManager.Object, mockIAuthenticationManager.Object); mockApplicationSignInManager.Setup(x => x.PasswordSignInAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <bool>())) .ReturnsAsync(SignInStatus.Failure); _accountController = new AccountController(mockApplicationUserManager.Object, mockApplicationSignInManager.Object, mockIAuthenticationManager.Object); var viewModel = new AccountRegisterViewModel() { Email = "email", Password = "******", ConfirmPassword = "******" }; var result = await _accountController.Register(viewModel); Assert.IsInstanceOf <ViewResult>(result); }
public void CanDeserializeDictionaryOfComplexTypes() { JsConfig.ConvertObjectTypesIntoStringDictionary = true; var dict = new Dictionary <string, object>(); dict["ChildDict"] = new Dictionary <string, object> { { "age", 12 }, { "name", "mike" } }; dict["ChildIntList"] = new List <int> { 1, 2, 3 }; dict["ChildStringList"] = new List <string> { "a", "b", "c" }; dict["ChildObjectList"] = new List <object> { 1, "cat", new Dictionary <string, object> { { "s", "s" }, { "n", 1 } } }; var serialized = JsonSerializer.SerializeToString(dict); var deserialized = JsonSerializer.DeserializeFromString <Dictionary <string, object> >(serialized); Assert.IsNotNull(deserialized["ChildDict"]); Assert.IsInstanceOf <Dictionary <string, object> >(deserialized["ChildDict"]); Assert.AreEqual("12", ((IDictionary)deserialized["ChildDict"])["age"]); Assert.AreEqual("mike", ((IDictionary)deserialized["ChildDict"])["name"]); }
public void CreateNode_WasCalled_ReturnXmlNode() { var result = XmlUtility.CreateNode("test", _document); Assert.IsInstanceOf <XmlNode>(result); Assert.That(result.Name, Is.EqualTo("test")); }
public void DevelopmentPlanIndexViewContainsListOfDevelopmentPlanModel() { //Arrange var mock = new Mock <IDevelopmentPlanRepository>(); mock.Setup(d => d.DevelopmentPlans).Returns(new[] { new DevelopmentPlan { Id = 1, EmployeeId = 2 }, new DevelopmentPlan { Id = 2, EmployeeId = 4 }, new DevelopmentPlan { Id = 3, EmployeeId = 1 } }.AsQueryable()); var controller = new DevelopmentPlanController(mock.Object); //Act var actual = (List <DevelopmentPlan>)controller.Index().Model; //Assert Assert.IsNotNull(actual); Assert.IsInstanceOf <List <DevelopmentPlan> >(actual); }
public async Task AutheficationWhenDataInvalid_ExpectedNotOKModel() { //Arrange var loginModel = new UserLoginViewModel() { Email = "*****@*****.**", Password = "", RememberMe = false }; var userManager = FakeTestingService.MockUserManager <User>(_users); userManager.Setup(m => m.FindByEmailAsync(It.IsAny <string>())) .ReturnsAsync(null as User); var signInManager = FakeTestingService.MockSightInManager <User>(userManager.Object); signInManager.Setup(m => m.PasswordSignInAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <bool>())) .ReturnsAsync(SignInResult.Success); var accaunt = new preparation.Controllers.AccountController(userManager.Object, signInManager.Object); string testRedirect = "/"; //Actual var actual = await accaunt.Login(loginModel, testRedirect); //Assert var actualVuewResult = actual as ViewResult; NAssert.IsInstanceOf(typeof(ViewResult), actual); NAssert.IsAssignableFrom(typeof(UserLoginViewModel), actualVuewResult.ViewData.Model); NAssert.True(actualVuewResult.ViewData.ModelState.ErrorCount > 0); }
public void _SaveGeneralInfo_ValidRequest_ReturnsJsonResult() { // Arrange var @event = new Event(); @event.FillWithDefaultValues(); @event = _context.Events.Add(@event); var edition = new Edition(); edition.FillWithDefaultValues(@event); edition = _context.Editions.Add(edition); var editionTranslation = new EditionTranslation(); editionTranslation.FillWithDefaultValues(edition); _context.EditionTranslations.Add(editionTranslation); var eventDirector = new EventDirector(); eventDirector.FillWithDefaultValues(@event); eventDirector.IsPrimary = true; _context.EventDirectors.Add(eventDirector); _context.SaveChanges(); var model = Mapper.Map <Edition, EditionEditGeneralInfoModel>(edition); // Act var result = _controller._SaveGeneralInfo(model); // Assert Assert.IsInstanceOf <JsonResult>(result); Assert.IsTrue(result.GetValue <bool>("success")); }
public void EmployeeIndexViewContainsListOfEmployeeModel() { //Arrange var mock = new Mock <IEmployeeRepository>(); mock.Setup(e => e.Employees).Returns(new[] { new Employee { Id = 1, Name = "AA", ManagerId = 2 }, new Employee { Id = 2, Name = "BB", ManagerId = 1 }, new Employee { Id = 3, Name = "CC", ManagerId = 3 } }.AsQueryable()); var controller = new EmployeeController(mock.Object); //Act var actual = (List <Employee>)controller.Index().Model; //Assert Assert.IsInstanceOf <List <Employee> >(actual); }
public void GetXmlNodeByName_ChildExistRecursive_ReturnXmlNode() { var result = XmlUtility.GetXmlNodeByName(_document.DocumentElement, "level2"); Assert.IsInstanceOf <XmlNode>(result); Assert.That(result.Name, Is.EqualTo("level2")); }
public void Edit_ValidRequest_ReturnsEditionEditModel() { // Arrange var @event = new Event(); @event.FillWithDefaultValues(); @event = _context.Events.Add(@event); var edition = new Edition(); edition.FillWithDefaultValues(@event); edition = _context.Editions.Add(edition); var eventDirector = new EventDirector(); eventDirector.FillWithDefaultValues(@event); _context.EventDirectors.Add(eventDirector); _context.SaveChanges(); // Act var result = _controller.Edit(edition.EditionId, null); // Assert Assert.IsInstanceOf <EditionEditModel>(((ViewResult)result).Model); Assert.AreEqual(edition.EditionId, ((EditionEditModel)((ViewResult)result).Model).EditionId); }
public void Delete_ValidRequest_RedirectsToIndexAction() { // Arrange var @event = new Event(); @event.FillWithDefaultValues(); @event = _context.Events.Add(@event); var edition = new Edition(); edition.FillWithDefaultValues(@event); edition.Status = (byte)EditionStatusType.Draft.GetHashCode(); edition = _context.Editions.Add(edition); var eventDirector = new EventDirector(); eventDirector.FillWithDefaultValues(@event); eventDirector.IsPrimary = true; _context.EventDirectors.Add(eventDirector); _context.SaveChanges(); // Act var result = _controller.Delete(edition.EditionId); // Assert Assert.IsInstanceOf <RedirectToRouteResult>(result); }
public void MyProjectsTest() { using (var mock = AutoMock.GetLoose()) { mock.Mock <IRepository <Project> >() .Setup(projectsRepository => projectsRepository.GetList()) .Returns(GetSampleProjects()); var identity = new GenericIdentity("test_user"); identity.AddClaim(new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", Guid.NewGuid().ToString())); var principal = new GenericPrincipal(identity, new[] { "user" }); var httpCtxStub = new Mock <HttpContextBase>(); httpCtxStub.SetupGet(p => p.User).Returns(principal); var controllerCtx = new ControllerContext { HttpContext = httpCtxStub.Object }; _homeController = mock.Create <HomeController>(); _homeController.ControllerContext = controllerCtx; var result = _homeController.MyProjects(); Assert.IsInstanceOf <ViewResult>(result); } }
public void Index_ValidRequest_ReturnsEditionIndexModel() { // Arrange var @event = new Event(); @event.FillWithDefaultValues(); @event = _context.Events.Add(@event); var edition = new Edition(); edition.FillWithDefaultValues(@event); edition = _context.Editions.Add(edition); var eventDirector = new EventDirector(); eventDirector.FillWithDefaultValues(@event); _context.EventDirectors.Add(eventDirector); _context.SaveChanges(); // Act var result = _controller.Index(edition.EventId); // Assert Assert.IsInstanceOf <EditionIndexModel>(result.Model); Assert.AreEqual(1, ((EditionIndexModel)result.Model).Editions.Count); }
public IEnumerator ItDoesntReceiveMessageForDifferentChannel() { CreateClient(ChannelParameterOne); yield return(WaitForClientToSettle()); Assert.IsEmpty(client.receivedMessages); yield return(OnFacet <BroadcastingFacet> .Call( nameof(BroadcastingFacet.SendMyMessage), ChannelParameterTwo, // TWO "Send to another channel" ).AsCoroutine()); // send one message afterwards for which we can wait yield return(OnFacet <BroadcastingFacet> .Call( nameof(BroadcastingFacet.SendMyMessage), ChannelParameterOne, "Hello world!" ).AsCoroutine()); // wait for the one message yield return(WaitForMessages(1)); // and check it's the hello-world one Assert.AreEqual(1, client.receivedMessages.Count); Assert.IsInstanceOf <MyMessage>(client.receivedMessages[0]); Assert.AreEqual( "Hello world!", ((MyMessage)client.receivedMessages[0]).foo ); yield return(null); }
public void AddProjectModelStateErrorTest() { using (var mock = AutoMock.GetLoose()) { mock.Mock <IRepository <Client> >() .Setup(c => c.GetList()) .Returns(GetSampleClients()); var identity = new GenericIdentity("test_user"); identity.AddClaim(new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", Guid.NewGuid().ToString())); var principal = new GenericPrincipal(identity, new[] { "user" }); var httpCtxStub = new Mock <HttpContextBase>(); httpCtxStub.SetupGet(p => p.User).Returns(principal); var controllerCtx = new ControllerContext { HttpContext = httpCtxStub.Object }; _homeController = mock.Create <HomeController>(); _homeController.ModelState.AddModelError("key", "error message"); _homeController.ControllerContext = controllerCtx; var viewModel = new AddProjectViewModel() { Project = new Project() }; var result = _homeController.Add(viewModel); Assert.IsInstanceOf <ViewResult>(result); } }
public void TestGetUserSkills() { var controller = new AccountController(); var result = controller.GetUserSkills("ASP.NET"); Assert.IsInstanceOf(typeof(Task <JsonResult>), result); }
public IEnumerator PendingSubscriptionsWork() { /* * Sending a message into the channel just after subscription * should be received by the client even though the client starts * handling the subscription only after the message is already sent. */ // SETUP: establish the SSE connection so that the server // will send us the message even though we don't handle the // subscription yet. Without an existing connection the message // would be buffered on the server. CreateClient("completely-different-channel", false); yield return(WaitForClientToSettle()); client = null; // now the proper test: CreateClient(ChannelParameterOne, true); yield return(WaitForClientToSettle()); yield return(WaitForMessages(1)); Assert.AreEqual(1, client.receivedMessages.Count); Assert.IsInstanceOf <MyMessage>(client.receivedMessages[0]); Assert.AreEqual( "Message after subscribing", ((MyMessage)client.receivedMessages[0]).foo ); yield return(null); }
public void TestChangeProfilePicture2() { var controller = new AccountController { ControllerContext = MockControllerContext() }; Mock <ControllerContext> cc = new Mock <ControllerContext>(); UTF8Encoding enc = new UTF8Encoding(); Mock <HttpPostedFileBase> file1 = new Mock <HttpPostedFileBase>(); file1.Expect(d => d.FileName).Returns("~/Content/images/DefaultProfile.jpg"); file1.Expect(d => d.ContentType).Returns("image/jpeg"); file1.Expect(d => d.InputStream).Returns(new MemoryStream(enc.GetBytes("~/Content/images/DefaultProfile.jpg"))); cc.Expect(d => d.HttpContext.Request.Files.Count).Returns(2); cc.Expect(d => d.HttpContext.Request.Files[0]).Returns(file1.Object); var principal = new Mock <IPrincipal>(); principal.Setup(p => p.IsInRole("user")).Returns(true); principal.SetupGet(x => x.Identity.Name).Returns("beastmaster"); cc.SetupGet(x => x.HttpContext.User).Returns(principal.Object); controller.ControllerContext = cc.Object; var result = controller.ChangeProfilePicture(); Assert.IsInstanceOf(typeof(Task <ActionResult>), result); }
public void TestExpandPost() { var controller = new AccountController(); var result = controller.ExpandPost("beastmaster", 0); Assert.IsInstanceOf(typeof(Task <ActionResult>), result); }
public void TestCreatePassword() { var controller = new AccountController(); var result = controller.CreatePassword(); Assert.IsInstanceOf(typeof(string), result); }
public void TestRegisteredUsers() { var controller = new AccountController(); var result = controller.RegisteredUsers(); Assert.IsInstanceOf(typeof(ViewResult), result); }
public void GetXmlNodeByAttribute_NodeWithAttributeExist_ReturnXmlNode() { var result = XmlUtility.GetXmlNodeByAttribute(_document.DocumentElement, "level2", "type", "l2"); Assert.IsInstanceOf <XmlNode>(result); Assert.That(result.Name, Is.EqualTo("level2")); }
public void TestComponentsGuide2() { var controller = new HomeController(); var result = controller.ComponentsGuide(null); Assert.IsInstanceOf(typeof(ViewResult), result); }
public void TestChat() { var controller = new HomeController(); var result = controller.Chat() as ViewResult; Assert.IsInstanceOf(typeof(ViewResult), result); }
public void TestTeamManagement() { var controller = new HomeController(); var result = controller.TeamManagement("KiranRambha") as ViewResult; Assert.IsInstanceOf(typeof(ViewResult), result); }