Exemple #1
0
        public void AddGetTest()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                LoginApplicationUserAndSetSessionVariables();
                TaxonController controller     = new TaxonController();
                string          controllerName = "Taxon";
                string          actionName     = "Add";
                controller.ControllerContext = GetShimControllerContext(actionName, controllerName);
                SessionRevisionId            = DyntaxaTestSettings.Default.TestRevisionOngoingId;

                // Act
                var addResult    = controller.Add(DyntaxaTestSettings.Default.TestTaxonId.ToString()) as ViewResult;
                var addViewModel = addResult.ViewData.Model as TaxonAddViewModel;


                // Assert
                Assert.IsNotNull(addResult);

                Assert.IsNotNull(addViewModel);

                // Test that correct view is returned
                Assert.AreEqual("Add", addResult.ViewName);

                // Test model values
                Assert.AreEqual(DyntaxaTestSettings.Default.TestTaxonId, Convert.ToInt32(addViewModel.ParentTaxonId));
                Assert.AreEqual(String.Empty, addViewModel.Author);
                Assert.AreEqual(15, addViewModel.TaxonCategoryList.Count);
                Assert.AreEqual(String.Empty, addViewModel.Description);
                Assert.AreEqual(String.Empty, addViewModel.CommonName);
            }
        }
Exemple #2
0
        public void AddPostTest()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                LoginApplicationUserAndSetSessionVariables();

                // TODO this does not work; how do we set transactions to a user and shim them in code?
                Transaction = new ShimTransaction()
                {
                    Commit = () => { return; },
                };

                TaxonController controller     = new TaxonController();
                string          controllerName = "Taxon";
                string          actionName     = "Add";
                controller.ControllerContext = GetShimControllerContext(actionName, controllerName);

                ITaxonRevision refTaxonRevision = TaxonDataSourceTestRepositoryData.GetReferenceRevision(ApplicationUserContext, DyntaxaTestSettings.Default.TestTaxonId, TaxonRevisionStateId.Ongoing.ToString());
                ITaxon         refTaxon         = TaxonDataSourceTestRepositoryData.GetReferenceTaxon(ApplicationUserContext, DyntaxaTestSettings.Default.TestTaxonId);
                TaxonIdTuple   taxonIdentifier  = TaxonIdTuple.Create(refTaxon.ScientificName, refTaxon.Id);

                SessionRevision   = refTaxonRevision;
                SessionRevisionId = DyntaxaTestSettings.Default.TestRevisionOngoingId;
                SessionTaxonId    = taxonIdentifier;

                // Create model....
                TaxonAddViewModel model = new TaxonAddViewModel();
                model.ParentTaxonId   = DyntaxaTestSettings.Default.TestParentTaxonId.ToString();
                model.TaxonCategoryId = 14;
                model.ScientificName  = "New Parent";

                // Test 1: Model state is valid
                // Act
                var result = controller.Add(model) as RedirectToRouteResult;

                // Test that correct view is returned
                Assert.IsNotNull(result);

                Assert.AreEqual(DyntaxaTestSettings.Default.TestTaxonId.ToString(), result.RouteValues["taxonId"]);
                Assert.AreEqual("Edit", result.RouteValues["action"]);

                // Test 2: Model state is invalid
                // Act
                // Set model state to be invalid
                controller.ModelState.AddModelError("", "dummy error message");
                var addResult    = controller.Add(model) as ViewResult;
                var addViewModel = addResult.ViewData.Model as TaxonAddViewModel;


                // Assert
                Assert.IsNotNull(addResult);

                // Test that correct view is returned ie th add view is reloaded...
                Assert.AreEqual("Add", addResult.ViewName);

                Assert.IsNotNull(addViewModel);

                // Test that Imodel values.
                Assert.AreEqual(DyntaxaTestSettings.Default.TestParentTaxonId.ToString(), addViewModel.ParentTaxonId);
            }
        }