Ejemplo n.º 1
0
        public void AddParentGetTest()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                LoginApplicationUserAndSetSessionVariables();
                TaxonController controller     = new TaxonController();
                string          controllerName = "Taxon";
                string          actionName     = "AddParent";
                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;
                // Mock Controller
                //           builder.InitializeController(controller);

                // Test 1:
                // Act
                var addParentResult    = controller.AddParent(DyntaxaTestSettings.Default.TestTaxonId.ToString()) as ViewResult;
                var addParentViewModel = addParentResult.ViewData.Model as TaxonAddParentViewModel;


                // Assert
                Assert.IsNotNull(addParentResult);
                Assert.IsNotNull(addParentViewModel);

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

                // Test model values
                // TODO test more model values....

                Assert.IsNull(addParentViewModel.SelectedTaxonList);
                Assert.AreEqual(1, addParentViewModel.AvailableParents.Count);
                Assert.AreEqual(refTaxon.Id.ToString(), addParentViewModel.TaxonId);
                Assert.AreEqual(refTaxonRevision.Id.ToString(), addParentViewModel.RevisionId);

                foreach (TaxonParentViewModelHelper helper in addParentViewModel.TaxonList)
                {
                    Assert.IsNotNull(helper.Category);
                    Assert.IsNotNull(helper.CommonName);
                    Assert.IsNotNull(helper.SortOrder);
                    Assert.IsNotNull(helper.TaxonId);
                    Assert.IsNotNull(helper.ScientificName);
                }
            }
        }
Ejemplo n.º 2
0
        public void AddParentPostTest()
        {
            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     = "AddParent";
                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;


                // Mock Controller
                //            builder.InitializeController(controller);
                // Create model....
                TaxonAddParentViewModel model = new TaxonAddParentViewModel();
                model.TaxonId           = DyntaxaTestSettings.Default.TestTaxonId.ToString();
                model.RevisionId        = DyntaxaTestSettings.Default.TestRevisionOngoingId.ToString();
                model.SelectedTaxonList = new List <string>()
                {
                    DyntaxaTestSettings.Default.TestParentTaxonId.ToString()
                };


                // Act
                var addParentResult = controller.AddParent(model) as RedirectToRouteResult;

                // Test 1: Test Save button pressed

                // Assert
                Assert.IsNotNull(addParentResult);

                // Test that AddParent action is returned.
                Assert.AreEqual(refTaxon.Id.ToString(), addParentResult.RouteValues["taxonId"]);
                Assert.AreEqual("AddParent", addParentResult.RouteValues["action"]);

                // Test 2: No new parent seleceted reload view
                // Act
                model.SelectedTaxonList = null;
                var addParentResult2 = controller.AddParent(model) as RedirectToRouteResult;


                // Assert
                Assert.IsNotNull(addParentResult2);

                // Test that AddParent action is returned.
                Assert.AreEqual(refTaxon.Id.ToString(), addParentResult2.RouteValues["taxonId"]);
                Assert.AreEqual("AddParent", addParentResult.RouteValues["action"]);
            }
        }