/// <summary> /// Update business partner /// </summary> /// <param name="Individual"></param> /// <returns></returns> public IndividualResponse Update(IndividualViewModel individual) { IndividualResponse response = new IndividualResponse(); try { Individual createdIndividual = unitOfWork.GetIndividualsRepository().Update(individual.ConvertToIndividual()); unitOfWork.Save(); response.Individual = createdIndividual.ConvertToIndividualViewModel(); //Thread td = new Thread(() => //{ // var resp = FirebaseHelper.Send<IndividualViewModel>("Individuals", response.Individual); //}); //td.IsBackground = true; //td.Start(); response.Success = true; } catch (Exception ex) { response.Individual = new IndividualViewModel(); response.Success = false; response.Message = ex.Message; } return(response); }
public void ReturnProfileFormWithEmpty_WhenModelStatusIsInvalid() { // Arrange var mockedIndividualService = new Mock <IIndividualService>(); var mockedOrganizationService = new Mock <IOrganizationService>(); var mockedMapper = new Mock <IMapper>(); var mockedPhotoHelper = new Mock <IPhotoHelper>(); var mockedUserProvider = new Mock <IUserProvider>(); var controller = new IndividualController( mockedIndividualService.Object, mockedMapper.Object, mockedPhotoHelper.Object, mockedUserProvider.Object); controller.ModelState.AddModelError("test", "test"); var model = new IndividualViewModel(); var mockedUpload = new Mock <HttpPostedFileBase>(); // Act & Assert controller .WithCallTo(x => x.Submit(model, mockedUpload.Object)) .ShouldRenderView("ProfileForm"); //.ShouldRedirectTo<AccountController>(typeof(AccountController).GetMethod("ProfileForm")) //.WithRouteValue("model"); }
public ActionResult Create(IndividualViewModel model) { try { if (ModelState.IsValid) { var repository = new IndividualRepository(context); var emailExiste = repository.Query(x => x.Email == model.Email).Count > 0; if (!emailExiste) { var individual = MapperHelper.Map <Individual>(model); repository.Insert(individual); context.SaveChanges(); } else { ModelState.AddModelError("Email", "El correo electrónico esta ocupado"); return(View(model)); } } return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Submit(IndividualViewModel model, HttpPostedFileBase upload) { if (!ModelState.IsValid) { return(View("ProfileForm", model)); } var user = this.userProvider.FindByName(User.Identity.Name); if (user == null) { return(HttpNotFound()); } var individual = this.mapper.Map <Individual>(model); individual.CreatedOn = DateTime.Now; // add default photo if (upload != null && upload.ContentLength > 0) { var imageViewModel = this.photoHelper.UploadImage(upload); var image = this.mapper.Map <Image>(imageViewModel); individual.ProfileImage = image; } individual.User = user; //this.individualService.Create(individual); user.Individual = individual; user.IsCompleted = true; this.userProvider.Update(user); return(RedirectToAction("ProfileDetails", new { area = "User", username = user.UserName })); }
public static IndividualViewModel ConvertToIndividualViewModelLite(this Individual individual) { IndividualViewModel individualViewModel = new IndividualViewModel() { Id = individual.Id, Identifier = individual.Identifier, Code = individual.Code, Name = individual.Name, SurName = individual.SurName, DateOfBirth = individual.DateOfBirth, Address = individual.Address, Passport = individual.Passport, Interest = individual.Interest, License = individual.License, EmbassyDate = individual.EmbassyDate, VisaFrom = individual.VisaFrom, VisaTo = individual.VisaTo, WorkPermitFrom = individual.WorkPermitFrom, WorkPermitTo = individual.WorkPermitTo, Family = individual.Family, UpdatedAt = individual.UpdatedAt, CreatedAt = individual.CreatedAt }; return(individualViewModel); }
private IndividualViewModel CheckViewModel(IActionResult result) { ViewResult viewResult = Assert.IsType <ViewResult>(result); IndividualViewModel viewModel = Assert.IsAssignableFrom <IndividualViewModel>(viewResult.ViewData.Model); Assert.NotEmpty(viewModel.Breeds); return(viewModel); }
private IndividualViewModel GetIndividualViewModel(Individual individual, int includeAncestors = 0, bool includeFamilies = false) { var ind = individual.Clone(); ind.Facts = _factService.Get(ind.TreeId, f => f.OwnerId == ind.Id && f.OwnerType == EntityType.Individual).ToList(); var individualViewModel = new IndividualViewModel(ind); if (includeAncestors > 0) { if (individualViewModel.FatherId > 0) { individualViewModel.Father = GetIndividualViewModel(_individualService.Get(individualViewModel.FatherId, ind.TreeId), includeAncestors - 1); } if (individualViewModel.MotherId > 0) { individualViewModel.Mother = GetIndividualViewModel(_individualService.Get(individualViewModel.MotherId, ind.TreeId), includeAncestors - 1); } } if (includeFamilies) { individualViewModel.Families = new List <FamilyViewModel>(); var families = _familyService.Get(ind.TreeId, fam => ind.Sex == Sex.Male ? fam.HusbandId == ind.Id : fam.WifeId == ind.Id); foreach (var family in families) { individualViewModel.Families.Add(GetFamilyViewModel(family, ind.Sex)); } } individualViewModel.Facts = new List <FactViewModel>(); foreach (var fact in ind.Facts) { individualViewModel.Facts.Add(new FactViewModel(fact)); } if (ind.ImageId == -1) { individualViewModel.ImageUrl = (ind.Sex == Sex.Female) ? "DesktopModules/FTP/FamilyTreeProject/Images/female.png" : "DesktopModules/FTP/FamilyTreeProject/Images/male.png"; } else { var file = FileManager.Instance.GetFile(ind.ImageId); individualViewModel.ImageUrl = (file.PortalId == -1) ? Globals.HostPath + file.RelativePath : PortalSettings.HomeDirectory + file.RelativePath; } return(individualViewModel); }
public void ReturnPartialViewwithCorrectModel_WhenIsAjax() { // Arrange var username = "******"; var id = Guid.NewGuid(); var viewModel = new IndividualViewModel(); viewModel.Id = id; var mockedIndividualService = new Mock <IIndividualService>(); mockedIndividualService.Setup(x => x.GetById(It.IsAny <Guid>())).Returns(new SofiaDayAndNight.Data.Models.Individual()); mockedIndividualService.Setup(x => x.RemoveFriendship(It.IsAny <string>(), It.IsAny <Guid>())).Verifiable(); var mockedPhotoHelper = new Mock <IPhotoHelper>(); var mockedUserProvider = new Mock <IUserProvider>(); var mockedMapper = new Mock <IMapper>(); mockedMapper.Setup(x => x.Map <IndividualViewModel>(It.IsAny <SofiaDayAndNight.Data.Models.Individual>())).Returns(viewModel); var request = new Mock <HttpRequestBase>(); request.SetupGet(x => x.Headers).Returns( new WebHeaderCollection() { { "X-Requested-With", "XMLHttpRequest" } } ); var httpContext = new Mock <HttpContextBase>(); httpContext.SetupGet(x => x.Request).Returns(request.Object); var principal = new Mock <IPrincipal>(); var controllerContext = new Mock <ControllerContext>(); principal.SetupGet(x => x.Identity.Name).Returns(username); httpContext.SetupGet(x => x.User).Returns(principal.Object); controllerContext.SetupGet(x => x.HttpContext).Returns(httpContext.Object); var controller = new IndividualController( mockedIndividualService.Object, mockedMapper.Object, mockedPhotoHelper.Object, mockedUserProvider.Object); controller.ControllerContext = controllerContext.Object; //Act & Assert controller .WithCallTo(x => x.CancelFriendship(Guid.NewGuid())) .ShouldRenderPartialView("_IndividualInfoPartial") .WithModel <IndividualViewModel>(model => { Assert.AreEqual(viewModel.Id, model.Id); }); }
public ActionResult Delete(int id, IndividualViewModel model) { try { var repository = new IndividualRepository(context); var individual = MapperHelper.Map <Individual>(model); repository.Delete(individual); context.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public async Task <ActionResult> Post(IndividualViewModel model) { if (model == null) { return(Json(new { status = HttpStatusCode.BadRequest })); } var result = await _individualService.CreateIndividualsAsync(new List <IndividualViewModel>(){ model }); if (!result) { return(Json(new { status = HttpStatusCode.InternalServerError })); } return(Json(new { status = HttpStatusCode.Created })); }
public void ReturnViewWithCorrectModel_WhenUsernameMatch() { //Arrange var username = "******"; var model = new IndividualViewModel(); model.UserName = username; var mockedIndividualService = new Mock <IIndividualService>(); mockedIndividualService.Setup(x => x.GetByUsername(username)) .Returns(new SofiaDayAndNight.Data.Models.Individual()); mockedIndividualService.Setup(x => x.GetStatus(It.IsAny <string>(), model.Id)) .Returns(IndividualStatus.None); var mockedOrganizationService = new Mock <IOrganizationService>(); var mockedMapper = new Mock <IMapper>(); mockedMapper.Setup(x => x.Map <IndividualViewModel>( It.IsAny <SofiaDayAndNight.Data.Models.Individual>())) .Returns(model); var mockedPhotoHelper = new Mock <IPhotoHelper>(); var mockedUserProvider = new Mock <IUserProvider>(); var principal = new Mock <IPrincipal>(); var controllerContext = new Mock <ControllerContext>(); principal.SetupGet(x => x.Identity.Name).Returns(username); controllerContext.SetupGet(x => x.HttpContext.User).Returns(principal.Object); var controller = new IndividualController( mockedIndividualService.Object, mockedMapper.Object, mockedPhotoHelper.Object, mockedUserProvider.Object); controller.ControllerContext = controllerContext.Object; //Act & Assert controller .WithCallTo(x => x.ProfileDetails(username)) .ShouldRenderDefaultView() .WithModel <IndividualViewModel>(m => { Assert.AreEqual(model.UserName, m.UserName); Assert.AreEqual(model.Id, m.Id); }); }
public HttpResponseMessage SaveIndividual(IndividualViewModel viewModel) { Individual individual; if (viewModel.Id == -1) { individual = new Individual { Id = -1, TreeId = viewModel.TreeId, FirstName = viewModel.FirstName, LastName = viewModel.LastName }; switch (viewModel.Sex) { case "Male": individual.Sex = Sex.Male; break; case "Female": individual.Sex = Sex.Female; break; default: individual.Sex = Sex.Unknown; break; } _individualService.Add(individual); } else { individual = _individualService.Get(viewModel.Id, viewModel.TreeId); individual.FirstName = viewModel.FirstName; individual.LastName = viewModel.LastName; if (viewModel.ImageId > 0) { individual.ImageId = viewModel.ImageId; } _individualService.Update(individual); } var response = new { id = individual.Id }; return(Request.CreateResponse(HttpStatusCode.OK, response)); }
public int GetIndividualsCount(string searchParameter = "") { IndividualViewModel filterObject = JsonConvert.DeserializeObject <IndividualViewModel>(searchParameter); return(context.Individuals .Where(x => x.Active == true) .Where(x => filterObject == null || String.IsNullOrEmpty(filterObject.SearchBy_Code) || x.Code.ToString().ToLower().Contains(filterObject.SearchBy_Code.ToLower())) .Where(x => filterObject == null || String.IsNullOrEmpty(filterObject.SearchBy_Name) || x.Name.ToLower().Contains(filterObject.SearchBy_Name.ToLower())) .Where(x => filterObject == null || String.IsNullOrEmpty(filterObject.SearchBy_SurName) || x.SurName.ToLower().Contains(filterObject.SearchBy_SurName.ToLower())) .Where(x => filterObject == null || String.IsNullOrEmpty(filterObject.SearchBy_Interest) || x.Interest.ToLower().Contains(filterObject.SearchBy_Interest.ToLower())) .Where(x => filterObject == null || filterObject.SearchBy_VisaFrom == null || x.VisaFrom.Date >= filterObject.SearchBy_VisaFrom) .Where(x => filterObject == null || filterObject.SearchBy_VisaTo == null || x.VisaTo.Date <= filterObject.SearchBy_VisaTo) .Where(x => filterObject == null || filterObject.SearchBy_PermitFrom == null || x.WorkPermitFrom.Date >= filterObject.SearchBy_PermitFrom) .Where(x => filterObject == null || filterObject.SearchBy_PermitTo == null || x.WorkPermitTo.Date <= filterObject.SearchBy_PermitTo) .Count()); }
public async void GetEditFound() { using (var database = new TestDb()) { var controller = new IndividualsController(database.Context); IActionResult result = await controller.Edit(2); IndividualViewModel viewModel = CheckViewModel(result); Individual individual = database.Context.Individuals.SingleOrDefault(i => i.Id == 2); Assert.Equal(2, viewModel.Individual.Id); Assert.Equal(individual.Name, viewModel.Individual.Name); Assert.NotEmpty(viewModel.Breeds); } }
// GET: Individual /// <summary> /// Lista de individuals y se la va a pasar a la vista Index /// </summary> /// <returns></returns> public ActionResult Index() { try { var repository = new IndividualRepository(context); var individuals = repository.GetAll(); var models = MapperHelper.Map <IEnumerable <IndividualViewModel> >(individuals); return(View(models)); } catch (Exception ex) { var model = new IndividualViewModel(); ViewBag.ErrorMessage = ex.Message; return(View(model)); } }
public async void GetDeleteFound() { using (var database = new TestDb()) { var controller = new IndividualsController(database.Context); IActionResult result = await controller.Delete(10); IndividualViewModel viewModel = CheckViewModel(result); Individual individual = database.Context.Individuals.SingleOrDefault(i => i.Id == 10); Assert.Equal(10, viewModel.Individual.Id); Assert.Equal(individual.Name, viewModel.Individual.Name); Assert.Equal(individual.BreedId, viewModel.Individual.Breed.Id); } }
public void GetCreate() { using (var database = new TestDb()) { var controller = new IndividualsController(database.Context); IActionResult result = controller.Create(); IndividualViewModel viewModel = CheckViewModel(result); Assert.Equal(0, viewModel.Individual.Id); Assert.Equal(0, viewModel.Individual.Breed.Id); Assert.True(string.IsNullOrEmpty(viewModel.Individual.Name)); Assert.NotEmpty(viewModel.Breeds); } }
public ActionResult Edit(int id, IndividualViewModel model) { try { var repository = new IndividualRepository(context); ModelState.Remove("Email"); var entity = MapperHelper.Map <Individual>(model); repository.Update(entity); context.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View(new IndividualViewModel())); } }
/// <summary> /// Update business partner /// </summary> /// <param name="Individual"></param> /// <returns></returns> public IndividualResponse Update(IndividualViewModel Individual) { IndividualResponse response = new IndividualResponse(); try { response = WpfApiHandler.SendToApi <IndividualViewModel, IndividualResponse>(Individual, "Update"); response.Success = true; } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); }
public ActionResult Edit(int id) { if (id == 0) { return(HttpNotFound()); } var individual = _context.Individuals.SingleOrDefault(i => i.Id == id); if (individual == null) { return(HttpNotFound()); } var individualViewModel = new IndividualViewModel { Id = individual.Id, Name = individual.Name, Gender = individual.Gender, TelDirect = individual.TelDirect, TelDakheli = individual.TelDakheli, Mobile = individual.Mobile, Email = individual.Email, Description = individual.Description, SematId = individual.SematId ?? 0, Semats = _context.Semats.ToList(), SelectListItems = new List <SelectListItem> { new SelectListItem() { Text = "", Value = "" }, new SelectListItem() { Text = "زن", Value = "true" }, new SelectListItem() { Text = "مرد", Value = "false" } } //, Deleted = individual.Deleted }; return(View("IndividualForm", individualViewModel)); }
public static Individual MapViewModelToEntityModel(this IndividualViewModel model) { return(new Individual() { Email = model.Email, FirstName = model.FirstName, MiddleName = model.MiddleName, LastName = model.LastName, Address = model.Addresses?.Select(x => new Address() { AddressLine1 = x.AddressLine1, AddressLine2 = x.AddressLine2, City = x.City, State = x.State, Zip = x.Zip }).ToList() }); }
/// <summary> /// Deactivate business partner by id /// </summary> /// <param name="id"></param> /// <returns></returns> public IndividualResponse Delete(int id) { IndividualResponse response = new IndividualResponse(); try { IndividualViewModel viewModel = new IndividualViewModel(); viewModel.Id = id; response = WpfApiHandler.SendToApi <IndividualViewModel, IndividualResponse>(viewModel, "Delete"); response.Success = true; } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); }
public void CallUploadImage_WhenModelUploadIsValid() { // Arrange var username = "******"; var user = new User(); var viewModel = new IndividualViewModel(); var mockedIndividualService = new Mock <IIndividualService>(); var mockedPhotoHelper = new Mock <IPhotoHelper>(); var mockedUserProvider = new Mock <IUserProvider>(); mockedUserProvider.Setup(x => x.FindByName(It.IsAny <string>())).Returns(user); mockedUserProvider.Setup(x => x.Update(user)).Verifiable(); var mockedMapper = new Mock <IMapper>(); mockedMapper.Setup(x => x.Map <SofiaDayAndNight.Data.Models.Individual>(It.IsAny <IndividualViewModel>())) .Returns(new SofiaDayAndNight.Data.Models.Individual()); var mockedUpload = new Mock <HttpPostedFileBase>(); mockedUpload.SetupGet(x => x.ContentLength).Returns(1); mockedPhotoHelper.Setup(x => x.UploadImage(mockedUpload.Object)).Verifiable(); var principal = new Mock <IPrincipal>(); var controllerContext = new Mock <ControllerContext>(); principal.SetupGet(x => x.Identity.Name).Returns(username); controllerContext.SetupGet(x => x.HttpContext.User).Returns(principal.Object); var controller = new IndividualController( mockedIndividualService.Object, mockedMapper.Object, mockedPhotoHelper.Object, mockedUserProvider.Object); controller.ModelState.Clear(); controller.ControllerContext = controllerContext.Object; // Act controller.Submit(viewModel, mockedUpload.Object); // Assert mockedPhotoHelper.Verify(x => x.UploadImage(mockedUpload.Object), Times.Once); }
public NetworkViewModel GetNetwork(int id) { NetworkViewModel users = new NetworkViewModel { Individuals = new List <IndividualViewModel>(), Organizations = new List <OrganizationViewModel>() }; List <DbParameter> parameters = new List <DbParameter> { new SqlParameter(Constants.Individual.Id, id) }; using ( IDataReader reader = ExecuteReader(Constants.SPROC.GetUsersNetwork, DbCommandType.StoredProcedure, parameters)) { while (reader.Read()) { IndividualViewModel individual = new IndividualViewModel { Id = (int)reader[Constants.Individual.Id], Name = (string)reader[Constants.Individual.Name], Title = (string)reader[Constants.Individual.Title], Organisation = (string)reader[Constants.Individual.Organization] }; users.Individuals.Add(individual); } if (reader.NextResult()) { while (reader.Read()) { OrganizationViewModel organization = new OrganizationViewModel { Id = (int)reader[Constants.Organization.Id], Name = (string)reader[Constants.Organization.Name], Description = (string)reader[Constants.Organization.Description] }; users.Organizations.Add(organization); } } } return(users); }
public JsonResult Delete([FromBody] IndividualViewModel c) { IndividualResponse response; try { response = this.individualService.Delete(c.Id); } catch (Exception ex) { response = null; Console.WriteLine(ex.Message); } return(Json(response, new Newtonsoft.Json.JsonSerializerSettings() { Formatting = Newtonsoft.Json.Formatting.Indented })); }
public void CallMapMethod_WhenCollectionFound() { // Arrange var username = "******"; var model = new IndividualViewModel(); var mockedIndividualService = new Mock <IIndividualService>(); mockedIndividualService.Setup(x => x.GetFriendsRequests(username)) .Returns(new List <SofiaDayAndNight.Data.Models.Individual>() { new SofiaDayAndNight.Data.Models.Individual() }); var mockedOrganizationService = new Mock <IOrganizationService>(); var mockedMapper = new Mock <IMapper>(); mockedMapper.Setup(x => x.Map <IndividualViewModel>( It.IsAny <SofiaDayAndNight.Data.Models.Individual>())) .Returns(model); var mockedPhotoHelper = new Mock <IPhotoHelper>(); var mockedUserProvider = new Mock <IUserProvider>(); //var principal = new Mock<IPrincipal>(); //var controllerContext = new Mock<ControllerContext>(); //principal.SetupGet(x => x.Identity.Name).Returns(username); //controllerContext.SetupGet(x => x.HttpContext.User).Returns(principal.Object); var controller = new IndividualController( mockedIndividualService.Object, mockedMapper.Object, mockedPhotoHelper.Object, mockedUserProvider.Object); //controller.ControllerContext = controllerContext.Object; // Act controller.FriendsRequest(username); // Assert mockedMapper.Verify(x => x.Map <IndividualViewModel>( It.IsAny <SofiaDayAndNight.Data.Models.Individual>()), Times.Once); }
public void CallMapMethod_WhenUsernameMatch() { var username = "******"; var model = new IndividualViewModel(); var mockedIndividualService = new Mock <IIndividualService>(); mockedIndividualService.Setup(x => x.GetByUsername(username)) .Returns(new SofiaDayAndNight.Data.Models.Individual()); mockedIndividualService.Setup(x => x.GetStatus(It.IsAny <string>(), model.Id)) .Returns(IndividualStatus.None); var mockedOrganizationService = new Mock <IOrganizationService>(); var mockedMapper = new Mock <IMapper>(); mockedMapper.Setup(x => x.Map <IndividualViewModel>( It.IsAny <SofiaDayAndNight.Data.Models.Individual>())) .Returns(model); var mockedPhotoHelper = new Mock <IPhotoHelper>(); var mockedUserProvider = new Mock <IUserProvider>(); var principal = new Mock <IPrincipal>(); var controllerContext = new Mock <ControllerContext>(); principal.SetupGet(x => x.Identity.Name).Returns(username); controllerContext.SetupGet(x => x.HttpContext.User).Returns(principal.Object); var controller = new IndividualController( mockedIndividualService.Object, mockedMapper.Object, mockedPhotoHelper.Object, mockedUserProvider.Object); controller.ControllerContext = controllerContext.Object; // Act controller.ProfileDetails(username); // Assert mockedMapper.Verify(x => x.Map <IndividualViewModel>( It.IsAny <SofiaDayAndNight.Data.Models.Individual>()), Times.Once); }
public ActionResult Delete(int id, IndividualViewModel model) { try { var repo = new IndividualRepository(context); //if (ModelState.IsValid) //{ var individual = MapperHelpers.Map <Individual>(model); repo.Delete(individual); context.SaveChanges(); //} // TODO: Add delete logic here return(RedirectToAction("Index")); } catch { return(View()); } }
public async Task <ActionResult> Create(IndividualViewModel model, HttpPostedFileBase pimage) { if (ModelState.IsValid) { string img = ""; if (pimage != null) { Guid g; g = Guid.NewGuid(); img = System.IO.Path.GetFileName(pimage.FileName); img = g + img; /*Saving the file in server folder*/ pimage.SaveAs(Server.MapPath("~/Images/Profile/" + img)); } else { img = "ProfileImage.jpg"; } var admin = db.Users.FirstOrDefault(x => x.UserName == User.Identity.Name); var userStore = new UserStore <ApplicationUser>(db); var UserManager = new UserManager <ApplicationUser>(userStore); var user = new ApplicationUser { UserName = model.Email, Email = model.Email, Phone = model.Phone, Skype = model.Skype, Twitter = model.Twitter, Instagram = model.Instagram, FirstName = model.FirstName, LastName = model.LastName, PhoneNumber = model.Phone, ProfileImage = img, AgencyId = admin.AgencyId, IsAgencyAdmin = false }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("Index", "Dashboard")); } AddErrors(result); } return(View(model)); }
public void ReturnNotFoundRequest_WhenUserNotFound() { // Arrange var username = "******"; var user = new User(); var viewModel = new IndividualViewModel(); var mockedIndividualService = new Mock <IIndividualService>(); var mockedOrganizationService = new Mock <IOrganizationService>(); var mockedPhotoHelper = new Mock <IPhotoHelper>(); var mockedUserProvider = new Mock <IUserProvider>(); mockedUserProvider.Setup(x => x.FindByName(It.IsAny <string>())).Returns((User)null); mockedUserProvider.Setup(x => x.Update(user)).Verifiable(); var mockedMapper = new Mock <IMapper>(); mockedMapper.Setup(x => x.Map <SofiaDayAndNight.Data.Models.Individual>(It.IsAny <IndividualViewModel>())) .Returns(new SofiaDayAndNight.Data.Models.Individual()); var mockedUpload = new Mock <HttpPostedFileBase>(); var principal = new Mock <IPrincipal>(); var controllerContext = new Mock <ControllerContext>(); principal.SetupGet(x => x.Identity.Name).Returns(username); controllerContext.SetupGet(x => x.HttpContext.User).Returns(principal.Object); var controller = new IndividualController( mockedIndividualService.Object, mockedMapper.Object, mockedPhotoHelper.Object, mockedUserProvider.Object); controller.ModelState.Clear(); controller.ControllerContext = controllerContext.Object; //Act & Assert controller .WithCallTo(x => x.Submit(viewModel, mockedUpload.Object)) .ShouldGiveHttpStatus(404); }