Esempio n. 1
0
 private void ManageSurvey_Click(object sender, RoutedEventArgs e)
 {
     if (!int.TryParse(SurveyTime.Text, out int time))
     {
         MessageBox.Show(LangPages.MBox.TimeEntryError);
         return;
     }
     if (time <= 0)
     {
         MessageBox.Show("Ошибка ввода времени");
     }
     if (string.IsNullOrEmpty(SurveyName.Text))
     {
         MessageBox.Show(LangPages.MBox.ErrorEnteringPollName);
         return;
     }
     if ((bool)ManageSurvey.Tag)
     {
         _survey.Name = SurveyName.Text;
         _survey.Time = time;
         surveyController.Add(_survey);
         ManageSurvey.Tag      = false;
         GridSurvey.Visibility = Visibility.Visible;
     }
     else
     {
         _survey.Name = SurveyName.Text;
         _survey.Time = time;
         surveyController.Edit(_survey);
     }
 }
Esempio n. 2
0
        public void Edit_ServiceOK_ReturnsSuccessJson()
        {
            var id     = Guid.NewGuid();
            var survey = new Survey()
            {
                Id = id, Owner = new ApplicationUser()
                {
                    UserName = "******"
                }
            };
            var newData = new SurveyEditViewModel()
            {
            };

            var dbMock = new Mock <IApplicationDBContext>();

            var surveysMock = new Mock <ISurveyService>();

            surveysMock.Setup(s => s.FindAsync(id.ToString())).ReturnsAsync(survey);

            var securityMock = new Mock <ISecurity>();

            securityMock.SetupGet(s => s.UserName).Returns("Tyler");

            var subject = new SurveyController(dbMock.Object, surveysMock.Object, securityMock.Object);

            var result = subject.Edit(id.ToString(), newData).Result;

            surveysMock.Verify(s => s.EditAsync(survey, newData));
            Assert.IsInstanceOfType(result, typeof(JsonResult));
            dynamic jsonData = (result as JsonResult).Data;

            Assert.IsNotNull(jsonData.success);
        }
Esempio n. 3
0
        public void Edit_ServiceException_ReturnsErrorJson()
        {
            var id     = Guid.NewGuid();
            var survey = new Survey()
            {
                Id = id, Owner = new ApplicationUser()
                {
                    UserName = "******"
                }
            };
            var newData = new SurveyEditViewModel()
            {
            };
            var error = "Bad data!";

            var dbMock = new Mock <IApplicationDBContext>();

            var surveysMock = new Mock <ISurveyService>();

            surveysMock.Setup(s => s.FindAsync(id.ToString())).ReturnsAsync(survey);
            surveysMock.Setup(s => s.EditAsync(survey, newData)).Throws(new SurveyException(error));

            var securityMock = new Mock <ISecurity>();

            securityMock.SetupGet(s => s.UserName).Returns("Tyler");

            var subject = new SurveyController(dbMock.Object, surveysMock.Object, securityMock.Object);

            var result = subject.Edit(id.ToString(), newData).Result;

            Assert.IsInstanceOfType(result, typeof(JsonResult));
            dynamic jsonData = (result as JsonResult).Data;

            Assert.AreEqual(error, jsonData.error);
        }
Esempio n. 4
0
        public void Edit_WrongUser_Returns403()
        {
            var id     = Guid.NewGuid();
            var survey = new Survey()
            {
                Id = id, Owner = new ApplicationUser()
                {
                    UserName = "******"
                }
            };

            var dbMock = new Mock <IApplicationDBContext>();

            var surveysMock = new Mock <ISurveyService>();

            surveysMock.Setup(s => s.FindAsync(id.ToString())).ReturnsAsync(survey);

            var securityMock = new Mock <ISecurity>();

            securityMock.SetupGet(s => s.UserName).Returns("Peter");

            var subject = new SurveyController(dbMock.Object, surveysMock.Object, securityMock.Object);

            var result = subject.Edit(id.ToString(), new SurveyEditViewModel()).Result;

            Assert.IsInstanceOfType(result, typeof(HttpStatusCodeResult));
            Assert.AreEqual(403, (result as HttpStatusCodeResult).StatusCode);
        }
Esempio n. 5
0
        public void Edit_IdNotFound_Returns404()
        {
            var id = Guid.NewGuid();

            var surveysMock = new Mock <ISurveyService>();

            surveysMock.Setup(s => s.FindAsync(id.ToString())).ReturnsAsync((Survey)null);

            var dbMock = new Mock <IApplicationDBContext>();

            var subject = new SurveyController(dbMock.Object, surveysMock.Object, Mock.Of <ISecurity>());

            var result = subject.Edit(id.ToString(), new SurveyEditViewModel()).Result;

            Assert.IsInstanceOfType(result, typeof(HttpNotFoundResult));
        }
Esempio n. 6
0
        public void Edit_UserIsCoOwner_ResetsCoOwnersArgAndReturnsSuccessJson()
        {
            var id     = Guid.NewGuid();
            var survey = new Survey()
            {
                Id    = id,
                Owner = new ApplicationUser()
                {
                    UserName = "******"
                },
                SharedUsers = new[] { new ApplicationUser()
                                      {
                                          UserName = "******"
                                      } }
            };
            var newData = new SurveyEditViewModel()
            {
                SharedUsers = new[] { "Shannon", "Bill" }
            };

            var dbMock = new Mock <IApplicationDBContext>();

            var surveysMock = new Mock <ISurveyService>();

            surveysMock.Setup(s => s.FindAsync(id.ToString())).ReturnsAsync(survey);

            var securityMock = new Mock <ISecurity>();

            securityMock.SetupGet(s => s.UserName).Returns("Shannon");

            var subject = new SurveyController(dbMock.Object, surveysMock.Object, securityMock.Object);

            var result = subject.Edit(id.ToString(), newData).Result;

            surveysMock.Verify(s => s.EditAsync(survey,
                                                It.Is <SurveyEditViewModel>(vm =>
                                                                            vm == newData &&
                                                                            vm.SharedUsers.Count() == 1 &&
                                                                            vm.SharedUsers.First() == "Shannon")));
            Assert.IsInstanceOfType(result, typeof(JsonResult));
            dynamic jsonData = (result as JsonResult).Data;

            Assert.IsNotNull(jsonData.success);
        }