/// <summary> /// Method that returns a list of questions for a given hunt. /// </summary> /// <param name="hunt"></param> /// <returns></returns> public IEnumerable <question> GetHuntQuestions(hunt hunt) { using (var context = new TreasureHuntEntities()) { if (hunt == null) { return(null); } //Grab all of the question ids associated with a given hunt. var returnedquestionIds = context.huntquestions.Where(c => c.HuntId == hunt.HuntId).Select(s => s.QuestionId).ToList(); returnedquestionIds.ForEach(e => context.ObjectStateManager.ChangeObjectState(e, System.Data.EntityState.Detached)); List <question> returnedListOfQuestions = new List <question>(); //For each one of these ids foreach (var questionId in returnedquestionIds) { //Add to the list the question associated with this id. var question = context.questions.Where(c => c.QuestionId == questionId).Single(); context.ObjectStateManager.ChangeObjectState(question, System.Data.EntityState.Detached); returnedListOfQuestions.Add(question); } return(returnedListOfQuestions); } }
public void Setup() { serviceClient = new Mock<ITreasureHuntService>(); hunt newHunt = new hunt(); newHunt.HuntId = 1; newHunt.HuntName = "New hunt"; newHunt.HuntDescription = "Hunt description"; List<hunt> listOfHunts = new List<hunt>(); listOfHunts.Add(newHunt); serviceClient.Setup(s => s.GetTreasureHuntsForParticularUserAsync(It.IsAny<user>())) .Returns(Task.FromResult(listOfHunts.ToArray())); viewModel = new SearchHuntViewModel(serviceClient.Object); user fakeUser = new user(); fakeUser.Name = "Current users name"; fakeUser.UserId = 1; fakeUser.Password = "******"; CurrentUser = fakeUser; myFakeHunt1 = new hunt(); myFakeHunt1.HuntName = "My Fake Hunt 1"; myFakeHunt2 = new hunt(); myFakeHunt2.HuntName = "My Fake Hunt 2"; returnedHunts.Add(myFakeHunt1); returnedHunts.Add(myFakeHunt2); }
/// <summary> /// Method that will pull down all of the available treasure hunts from the database for a given administrator. /// </summary> public async void RefreshTreasureHunts() { PopupDisplayed = true; TreasureHunts = await this.serviceClient.GetTreasureHuntsForParticularUserAsync(this.currentUser); CurrentTreasureHunt = null; PopupDisplayed = false; }
public void Setup() { serviceClient = new Mock <ITreasureHuntService>(); viewModel = new LeaderboardViewModel(serviceClient.Object); myFakeHunt = new hunt(); myFakeHunt.HuntName = "My Fake Hunt"; CurrentTreasureHunt = myFakeHunt; }
/// <summary> /// Method that saves new hunt data into the 'hunts' table. /// </summary> /// <param name="newHunt"></param> /// <returns></returns> public long SaveNewHunt(hunt newHunt) { using (var context = new TreasureHuntEntities()) { context.hunts.AddObject(newHunt); context.SaveChanges(); context.ObjectStateManager.ChangeObjectState(newHunt, System.Data.EntityState.Added); return(newHunt.HuntId); } }
public void Setup() { serviceClient = new Mock<ITreasureHuntService>(); viewModel = new LeaderboardViewModel(serviceClient.Object); myFakeHunt = new hunt(); myFakeHunt.HuntName = "My Fake Hunt"; CurrentTreasureHunt = myFakeHunt; }
// Start is called before the first frame update void Start() { hunt[] hunts = new hunt[2]; hunts[0].setHuntName(huntNames[0]); Debug.Log(hunts[0].getHuntName()); /*canvasHolder = GameObject.Find(canvasName); * GameObject newPlaceHolder = Instantiate(placeHolder, canvasHolder.transform); * nameholders = placeHolder.transform.GetChild(0).gameObject; * hunts[0].getHuntName(nameholders); */ }
//-http://stackoverflow.com/questions/15576282/sorting-a-c-sharp-list-by-multiple-columns //-http://stackoverflow.com/questions/18525253/wpf-listt-sort /// <summary> /// Method that returns all the huntparticipant data for a given treasure hunt. /// </summary> /// <param name="currentTreasureHunt"></param> /// <returns></returns> public List <huntparticipant> GetHuntParticipants(hunt currentTreasureHunt) { using (var context = new TreasureHuntEntities()) { if (currentTreasureHunt == null) { return(null); } var returnedHuntParticipants = context.huntparticipants.Where(c => c.HuntId == currentTreasureHunt.HuntId).OrderByDescending(s => s.Tally).ThenBy(s => s.ElapsedTime).ToList(); returnedHuntParticipants.ForEach(e => context.ObjectStateManager.ChangeObjectState(e, System.Data.EntityState.Detached)); return(returnedHuntParticipants); } }
public List <long> GetHuntQuestions(hunt hunt) { using (var context = new TreasureHuntEntities()) { if (hunt == null) { return(null); } var returnedquestionIds = context.huntquestions.Where(c => c.HuntId == hunt.HuntId).Select(s => s.QuestionId).ToList(); returnedquestionIds.ForEach(e => context.ObjectStateManager.ChangeObjectState(e, System.Data.EntityState.Detached)); return(returnedquestionIds); } }
private void ExecuteLeaderboardCommand() { hunt currentHunt = CurrentTreasureHunt; Messenger.Default.Send <LeaderboardMessage>(new LeaderboardMessage() { CurrentHunt = currentHunt }); Messenger.Default.Send <UpdateViewMessage>(new UpdateViewMessage() { UpdateViewTo = "LeaderboardViewModel" }); }
public void Setup() { serviceClient = new Mock <ITreasureHuntService>(); viewModel = new SearchHuntViewModel(serviceClient.Object); myFakeHunt1 = new hunt(); myFakeHunt1.HuntName = "My Fake Hunt 1"; myFakeHunt2 = new hunt(); myFakeHunt2.HuntName = "My Fake Hunt 2"; returnedHunts.Add(myFakeHunt1); returnedHunts.Add(myFakeHunt2); }
public void Setup() { serviceClient = new Mock<ITreasureHuntService>(); viewModel = new SearchHuntViewModel(serviceClient.Object); myFakeHunt1 = new hunt(); myFakeHunt1.HuntName = "My Fake Hunt 1"; myFakeHunt2 = new hunt(); myFakeHunt2.HuntName = "My Fake Hunt 2"; returnedHunts.Add(myFakeHunt1); returnedHunts.Add(myFakeHunt2); }
//Change this to private and use reflection for testing public void ExecuteSaveHuntNameCommand() { if (!DoesHuntAlreadyExist(HuntName)) { hunt newHunt = new hunt(); newHunt.HuntName = this.huntName; newHunt.Password = this.Password; newHunt.HuntDescription = this.Description; long huntId = this.serviceClient.SaveNewHunt(newHunt); userrole newUserRole = this.serviceClient.GetUserRole(this.currentUser); userhunt newUserHunt = new userhunt(); newUserHunt.HuntId = huntId; newUserHunt.UserId = this.currentUser.UserId; newUserHunt.UserRoleId = newUserRole.UserRoleId; this.serviceClient.SaveUserHunt(newUserHunt); //Grabs the correct hunt's ID and passes it into the view hunt view. //Ensures that the hunt has been saved to the database before it goes and grab's it hunt huntToView = serviceClient.GetHuntBasedOnName(newHunt.HuntName); Messenger.Default.Send <UpdateViewMessage>(new UpdateViewMessage() { UpdateViewTo = "ViewHuntViewModel" }); Messenger.Default.Send <SelectedHuntMessage>(new SelectedHuntMessage() { CurrentHunt = huntToView }); Messenger.Default.Send <ViewUpdatedMessage>(new ViewUpdatedMessage() { UpdatedView = true }); HuntName = null; Password = null; RetypedPassword = null; Description = null; } else { String messageBoxText = "This hunt already exists in the database."; String caption = "Hunt Already Exists"; MessageBoxResult box = MessageBox.Show(messageBoxText, caption); HuntName = null; } }
public void generateHunts() { for (int i = 0; i < numbersOfHunts; i++) { hunters[i] = new hunt(); hunters[i].setHuntName(huntNames[i]); hunters[i].setHuntId(i); int huntId = hunters[i].getHuntId(); GameObject newPlaceHolder = Instantiate(placeHolder, canvasHolder.transform); Vector3 newPosition = newPlaceHolder.transform.position; newPosition.y = newPosition.y - (margin * i); newPlaceHolder.transform.position = newPosition; nameholders = newPlaceHolder.transform.GetChild(0).gameObject; hunters[i].getHuntName(nameholders); nameholders.GetComponent <Button>().onClick.AddListener(delegate { goToCluePage(huntId); }); } }
public void ShouldSaveNewTreasureHuntIfDoesNotAlreadyExist() { #region Setup variables userrole userRole = new userrole(); userRole.UserId = 1; userRole.RoleId = 1; userRole.UserRoleId = 1; hunt fakeHunt = new hunt(); fakeHunt.HuntId = 1; fakeHunt.HuntName = "this fake hunt"; hunt fakeHuntTwo = new hunt(); fakeHuntTwo.HuntId = 2; fakeHuntTwo.HuntName = "my second fake hunt"; user currentUser = new user(); currentUser.Name = "fake user"; currentUser.UserId = 1; List <hunt> listOfHunts = new List <hunt>(); listOfHunts.Add(fakeHuntTwo); this.HuntName = "This fake hunt"; this.CurrentUser = currentUser; this.Description = "Fake description"; long resultId = 1; #endregion //-http://stackoverflow.com/questions/20859639/using-moq-to-mock-an-asynchronous-method-for-a-unit-test serviceClient.Setup(s => s.GetTreasureHuntsForParticularUserAsync(currentUser)).Returns(Task.FromResult(listOfHunts.ToArray())); serviceClient.Setup(s => s.SaveNewHuntAsync(It.IsAny <hunt>())).Returns(Task.FromResult(resultId)); serviceClient.Setup(s => s.SaveUserHuntAsync(It.IsAny <userhunt>())).Returns(Task.FromResult("")); serviceClient.Setup(s => s.GetHuntBasedOnNameAsync(It.IsAny <string>(), It.IsAny <long>())).Returns(Task.FromResult(fakeHunt)); viewModel.ExecuteSaveCommand(); serviceClient.Verify(s => s.SaveNewHuntAsync(It.IsAny <hunt>()), Times.Exactly(1)); serviceClient.Verify(s => s.GetTreasureHuntsForParticularUserAsync(currentUser), Times.Exactly(1)); serviceClient.Verify(s => s.SaveUserHuntAsync(It.IsAny <userhunt>()), Times.Exactly(1)); serviceClient.Verify(s => s.GetHuntBasedOnNameAsync(It.IsAny <String>(), It.IsAny <long>()), Times.Exactly(1)); }
/// <summary> /// Method that navigates the administrator to the Leaderboard view associated with the current treasure hunt. /// </summary> private void ExecuteLeaderboardCommand() { if (connectionChecker.IsInternetConnected()) { hunt currentHunt = CurrentTreasureHunt; Messenger.Default.Send <LeaderboardMessage>(new LeaderboardMessage() { CurrentHunt = currentHunt }); Messenger.Default.Send <UpdateViewMessage>(new UpdateViewMessage() { UpdateViewTo = "LeaderboardViewModel" }); } else { MessageBoxResult messageBox = MessageBox.Show(connectionChecker.ShowConnectionErrorMessage()); } }
public void ShouldSaveNewTreasureHuntIfDoesNotAlreadyExist() { #region Setup variables userrole userRole = new userrole(); userRole.UserId = 1; userRole.RoleId = 1; userRole.UserRoleId = 1; hunt fakeHunt = new hunt(); fakeHunt.HuntId = 1; fakeHunt.HuntName = "this fake hunt"; hunt fakeHuntTwo = new hunt(); fakeHuntTwo.HuntId = 2; fakeHuntTwo.HuntName = "my second fake hunt"; user currentUser = new user(); currentUser.Name = "fake user"; currentUser.UserId = 1; List <hunt> listOfHunts = new List <hunt>(); listOfHunts.Add(fakeHuntTwo); this.HuntName = "This fake hunt"; this.CurrentUser = currentUser; this.Password = "******"; this.Description = "Fake description"; #endregion serviceClient.Setup(s => s.GetTreasureHunts()).Returns(listOfHunts.ToArray()); serviceClient.Setup(s => s.SaveNewHunt(It.IsAny <hunt>())).Returns(1); serviceClient.Setup(s => s.GetUserRole(It.IsAny <user>())).Returns(userRole); serviceClient.Setup(s => s.SaveUserHunt(It.IsAny <userhunt>())).Verifiable(); serviceClient.Setup(s => s.GetHuntBasedOnName(fakeHunt.HuntName)).Returns(fakeHunt); viewModel.ExecuteSaveHuntNameCommand(); serviceClient.Verify(s => s.SaveNewHunt(It.IsAny <hunt>()), Times.Exactly(1)); serviceClient.Verify(s => s.GetTreasureHunts(), Times.Exactly(1)); serviceClient.Verify(s => s.GetUserRole(It.IsAny <user>()), Times.Exactly(1)); serviceClient.Verify(s => s.SaveUserHunt(It.IsAny <userhunt>()), Times.Exactly(1)); serviceClient.Verify(s => s.GetHuntBasedOnName(It.IsAny <String>()), Times.Exactly(1)); }
/// <Summary> Method that saves a new hunt to the database. </Summary> private async void SaveNewHunt() { hunt newHunt = new hunt(); newHunt.HuntName = this.huntName; newHunt.HuntDescription = this.Description; newHunt.EndDate = EndDate; //Create it and save it to the database. long huntId = await this.serviceClient.SaveNewHuntAsync(newHunt); userhunt newUserHunt = new userhunt(); newUserHunt.HuntId = huntId; newUserHunt.UserId = this.currentUser.UserId; await this.serviceClient.SaveUserHuntAsync(newUserHunt); //Grab the correct hunt's ID and pass it into the view hunt view. hunt huntToView = await serviceClient.GetHuntBasedOnNameAsync(newHunt.HuntName, currentUser.UserId); PopupDisplayed = false; Messenger.Default.Send <UpdateViewMessage>(new UpdateViewMessage() { UpdateViewTo = "ViewHuntViewModel" }); Messenger.Default.Send <SelectedHuntMessage>(new SelectedHuntMessage() { CurrentHunt = huntToView }); Messenger.Default.Send <ViewUpdatedMessage>(new ViewUpdatedMessage() { UpdatedView = true }); HuntName = null; Description = null; EndDate = DateTime.Today; }
public void ShouldNotSaveNewTreasureHuntIfItAlreadyExists() { #region Setup variables userrole userRole = new userrole(); userRole.UserId = 1; userRole.RoleId = 1; userRole.UserRoleId = 1; hunt fakeHunt = new hunt(); fakeHunt.HuntId = 1; fakeHunt.HuntName = "This fake hunt"; user currentUser = new user(); currentUser.Name = "fake user"; currentUser.UserId = 1; List <hunt> listOfHunts = new List <hunt>(); listOfHunts.Add(fakeHunt); this.HuntName = fakeHunt.HuntName; this.CurrentUser = currentUser; //this.Password = "******"; this.Description = "Fake description"; long resultId = 1; #endregion serviceClient.Setup(s => s.GetTreasureHuntsForParticularUserAsync(currentUser)).Returns(Task.FromResult(listOfHunts.ToArray())); serviceClient.Setup(s => s.SaveNewHuntAsync(It.IsAny <hunt>())).Returns(Task.FromResult(resultId)); serviceClient.Setup(s => s.SaveUserHuntAsync(It.IsAny <userhunt>())).Returns(Task.FromResult("")); serviceClient.Setup(s => s.GetHuntBasedOnNameAsync(It.IsAny <string>(), It.IsAny <long>())).Returns(Task.FromResult(fakeHunt)); viewModel.ExecuteSaveCommand(); serviceClient.Verify(s => s.SaveNewHuntAsync(It.IsAny <hunt>()), Times.Exactly(0)); serviceClient.Verify(s => s.GetTreasureHuntsForParticularUserAsync(currentUser), Times.Exactly(1)); serviceClient.Verify(s => s.SaveUserHuntAsync(It.IsAny <userhunt>()), Times.Exactly(0)); serviceClient.Verify(s => s.GetHuntBasedOnNameAsync(It.IsAny <String>(), It.IsAny <long>()), Times.Exactly(0)); }
public void Setup() { serviceClient = new Mock <ITreasureHuntService>(); viewModel = new ViewHuntViewModel(serviceClient.Object); NewQuestion = newQuestion; myFakeHunt = new hunt(); myFakeHunt.HuntName = "My Fake Hunt"; myFakeQuestion = new question(); myFakeQuestion.Question1 = "This is my question"; myFakeQuestion.URL = "empty url"; returnedHunts.Add(myFakeHunt); returnedIds.Add(one); CurrentTreasureHunt = myFakeHunt; CurrentQuestion = myFakeQuestion; huntQuestions.Add(myFakeQuestion); Questions = huntQuestions.AsEnumerable(); }
public void Setup() { serviceClient = new Mock<ITreasureHuntService>(); viewModel = new ViewHuntViewModel(serviceClient.Object); NewQuestion = newQuestion; myFakeHunt = new hunt(); myFakeHunt.HuntName = "My Fake Hunt"; myFakeQuestion = new question(); myFakeQuestion.Question1 = "This is my user"; myFakeQuestion.URL = "empty url"; returnedHunts.Add(myFakeHunt); returnedIds.Add(one); CurrentTreasureHunt = myFakeHunt; CurrentQuestion = myFakeQuestion; huntQuestions.Add(myFakeQuestion); Questions = huntQuestions.AsEnumerable(); }
public void Setup() { serviceClient = new Mock <ITreasureHuntService>(); hunt newHunt = new hunt(); newHunt.HuntId = 1; newHunt.HuntName = "New hunt"; newHunt.HuntDescription = "Hunt description"; List <hunt> listOfHunts = new List <hunt>(); listOfHunts.Add(newHunt); serviceClient.Setup(s => s.GetTreasureHuntsForParticularUserAsync(It.IsAny <user>())) .Returns(Task.FromResult(listOfHunts.ToArray())); viewModel = new SearchHuntViewModel(serviceClient.Object); user fakeUser = new user(); fakeUser.Name = "Current users name"; fakeUser.UserId = 1; fakeUser.Password = "******"; CurrentUser = fakeUser; myFakeHunt1 = new hunt(); myFakeHunt1.HuntName = "My Fake Hunt 1"; myFakeHunt2 = new hunt(); myFakeHunt2.HuntName = "My Fake Hunt 2"; returnedHunts.Add(myFakeHunt1); returnedHunts.Add(myFakeHunt2); }
//Change this to private and use reflection for testing public void ExecuteSaveHuntNameCommand() { if (!DoesHuntAlreadyExist(HuntName)) { hunt newHunt = new hunt(); newHunt.HuntName = this.huntName; newHunt.Password = this.Password; newHunt.HuntDescription = this.Description; long huntId = this.serviceClient.SaveNewHunt(newHunt); userrole newUserRole = this.serviceClient.GetUserRole(this.currentUser); userhunt newUserHunt = new userhunt(); newUserHunt.HuntId = huntId; newUserHunt.UserId = this.currentUser.UserId; newUserHunt.UserRoleId = newUserRole.UserRoleId; this.serviceClient.SaveUserHunt(newUserHunt); //Grabs the correct hunt's ID and passes it into the view hunt view. //Ensures that the hunt has been saved to the database before it goes and grab's it hunt huntToView = serviceClient.GetHuntBasedOnName(newHunt.HuntName); Messenger.Default.Send<UpdateViewMessage>(new UpdateViewMessage() { UpdateViewTo = "ViewHuntViewModel" }); Messenger.Default.Send<SelectedHuntMessage>(new SelectedHuntMessage() { CurrentHunt = huntToView }); Messenger.Default.Send<ViewUpdatedMessage>(new ViewUpdatedMessage() { UpdatedView = true }); HuntName = null; Password = null; RetypedPassword = null; Description = null; } else { String messageBoxText = "This hunt already exists in the database."; String caption = "Hunt Already Exists"; MessageBoxResult box = MessageBox.Show(messageBoxText, caption); HuntName = null; } }
/// <Summary> Method that saves a new hunt to the database. </Summary> private async void SaveNewHunt() { hunt newHunt = new hunt(); newHunt.HuntName = this.huntName; newHunt.HuntDescription = this.Description; newHunt.EndDate = EndDate; //Create it and save it to the database. long huntId = await this.serviceClient.SaveNewHuntAsync(newHunt); userhunt newUserHunt = new userhunt(); newUserHunt.HuntId = huntId; newUserHunt.UserId = this.currentUser.UserId; await this.serviceClient.SaveUserHuntAsync(newUserHunt); //Grab the correct hunt's ID and pass it into the view hunt view. hunt huntToView = await serviceClient.GetHuntBasedOnNameAsync(newHunt.HuntName, currentUser.UserId); PopupDisplayed = false; Messenger.Default.Send<UpdateViewMessage>(new UpdateViewMessage() { UpdateViewTo = "ViewHuntViewModel" }); Messenger.Default.Send<SelectedHuntMessage>(new SelectedHuntMessage() { CurrentHunt = huntToView }); Messenger.Default.Send<ViewUpdatedMessage>(new ViewUpdatedMessage() { UpdatedView = true }); HuntName = null; Description = null; EndDate = DateTime.Today; }
private void ReceiveSelectedHuntMessage(hunt currentHunt) { this.currentTreasureHunt = currentHunt; RefreshQuestions(); }
private void ReceiveSelectedHuntMessage(hunt currentHunt) { this.currentTreasureHunt = currentHunt; }
//make internal public void RefreshTreasureHunts() { TreasureHunts = this.serviceClient.GetTreasureHuntsForParticularUser(this.currentUser); CurrentTreasureHunt = null; }
public void ShouldNotSaveNewTreasureHuntIfItAlreadyExists() { #region Setup variables userrole userRole = new userrole(); userRole.UserId = 1; userRole.RoleId = 1; userRole.UserRoleId = 1; hunt fakeHunt = new hunt(); fakeHunt.HuntId = 1; fakeHunt.HuntName = "This fake hunt"; user currentUser = new user(); currentUser.Name = "fake user"; currentUser.UserId = 1; List<hunt> listOfHunts = new List<hunt>(); listOfHunts.Add(fakeHunt); this.HuntName = fakeHunt.HuntName; this.CurrentUser = currentUser; this.Password = "******"; this.Description = "Fake description"; #endregion serviceClient.Setup(s => s.GetTreasureHunts()).Returns(listOfHunts.ToArray()); serviceClient.Setup(s => s.SaveNewHunt(It.IsAny<hunt>())).Returns(1); serviceClient.Setup(s => s.GetUserRole(It.IsAny<user>())).Returns(userRole); serviceClient.Setup(s => s.SaveUserHunt(It.IsAny<userhunt>())).Verifiable(); serviceClient.Setup(s => s.GetHuntBasedOnName(fakeHunt.HuntName)).Returns(fakeHunt); viewModel.ExecuteSaveHuntNameCommand(); serviceClient.Verify(s => s.GetTreasureHunts(), Times.Exactly(1)); serviceClient.Verify(s => s.SaveNewHunt(It.IsAny<hunt>()), Times.Exactly(0)); serviceClient.Verify(s => s.GetUserRole(It.IsAny<user>()), Times.Exactly(0)); serviceClient.Verify(s => s.SaveUserHunt(It.IsAny<userhunt>()), Times.Exactly(0)); serviceClient.Verify(s => s.GetHuntBasedOnName(It.IsAny<String>()), Times.Exactly(0)); }
/// <summary> /// Method used to receive an incoming SelectedHuntMessage to store the data related to the current /// hunt being accessed. It will also refresh from the database a list of currently available questions for the /// given hunt. /// </summary> /// <param name="currentHunt"></param> private void ReceiveSelectedHuntMessage(hunt currentHunt) { this.currentTreasureHunt = currentHunt; RefreshQuestions(); }
/// <summary> Method used to receive an incoming LeaderboardMessage to store the data related to the current /// hunt being accessed. </summary> private void ReceiveLeaderboardMessage(hunt currentHunt) { this.currentTreasureHunt = currentHunt; RefreshLeaderboard(); }
public void ShouldSaveNewTreasureHuntIfDoesNotAlreadyExist() { #region Setup variables userrole userRole = new userrole(); userRole.UserId = 1; userRole.RoleId = 1; userRole.UserRoleId = 1; hunt fakeHunt = new hunt(); fakeHunt.HuntId = 1; fakeHunt.HuntName= "this fake hunt"; hunt fakeHuntTwo = new hunt(); fakeHuntTwo.HuntId = 2; fakeHuntTwo.HuntName = "my second fake hunt"; user currentUser = new user(); currentUser.Name = "fake user"; currentUser.UserId = 1; List<hunt> listOfHunts = new List<hunt>(); listOfHunts.Add(fakeHuntTwo); this.HuntName = "This fake hunt"; this.CurrentUser = currentUser; this.Description = "Fake description"; long resultId = 1; #endregion //-http://stackoverflow.com/questions/20859639/using-moq-to-mock-an-asynchronous-method-for-a-unit-test serviceClient.Setup(s => s.GetTreasureHuntsForParticularUserAsync(currentUser)).Returns(Task.FromResult(listOfHunts.ToArray())); serviceClient.Setup(s => s.SaveNewHuntAsync(It.IsAny<hunt>())).Returns(Task.FromResult(resultId)); serviceClient.Setup(s => s.SaveUserHuntAsync(It.IsAny<userhunt>())).Returns(Task.FromResult("")); serviceClient.Setup(s => s.GetHuntBasedOnNameAsync(It.IsAny<string>(), It.IsAny<long>())).Returns(Task.FromResult(fakeHunt)); viewModel.ExecuteSaveCommand(); serviceClient.Verify(s => s.SaveNewHuntAsync(It.IsAny<hunt>()), Times.Exactly(1)); serviceClient.Verify(s => s.GetTreasureHuntsForParticularUserAsync(currentUser), Times.Exactly(1)); serviceClient.Verify(s => s.SaveUserHuntAsync(It.IsAny<userhunt>()), Times.Exactly(1)); serviceClient.Verify(s => s.GetHuntBasedOnNameAsync(It.IsAny<String>(), It.IsAny<long>()), Times.Exactly(1)); }
public void ShouldNotSaveNewTreasureHuntIfItAlreadyExists() { #region Setup variables userrole userRole = new userrole(); userRole.UserId = 1; userRole.RoleId = 1; userRole.UserRoleId = 1; hunt fakeHunt = new hunt(); fakeHunt.HuntId = 1; fakeHunt.HuntName = "This fake hunt"; user currentUser = new user(); currentUser.Name = "fake user"; currentUser.UserId = 1; List<hunt> listOfHunts = new List<hunt>(); listOfHunts.Add(fakeHunt); this.HuntName = fakeHunt.HuntName; this.CurrentUser = currentUser; //this.Password = "******"; this.Description = "Fake description"; long resultId = 1; #endregion serviceClient.Setup(s => s.GetTreasureHuntsForParticularUserAsync(currentUser)).Returns(Task.FromResult(listOfHunts.ToArray())); serviceClient.Setup(s => s.SaveNewHuntAsync(It.IsAny<hunt>())).Returns(Task.FromResult(resultId)); serviceClient.Setup(s => s.SaveUserHuntAsync(It.IsAny<userhunt>())).Returns(Task.FromResult("")); serviceClient.Setup(s => s.GetHuntBasedOnNameAsync(It.IsAny<string>(), It.IsAny<long>())).Returns(Task.FromResult(fakeHunt)); viewModel.ExecuteSaveCommand(); serviceClient.Verify(s => s.SaveNewHuntAsync(It.IsAny<hunt>()), Times.Exactly(0)); serviceClient.Verify(s => s.GetTreasureHuntsForParticularUserAsync(currentUser), Times.Exactly(1)); serviceClient.Verify(s => s.SaveUserHuntAsync(It.IsAny<userhunt>()), Times.Exactly(0)); serviceClient.Verify(s => s.GetHuntBasedOnNameAsync(It.IsAny<String>(), It.IsAny<long>()), Times.Exactly(0)); }