Beispiel #1
0
        public void DropParentGetTest()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                LoginApplicationUserAndSetSessionVariables();
                TaxonController controller     = new TaxonController();
                string          controllerName = "Taxon";
                string          actionName     = "DropParent";
                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 dropParentResult    = controller.DropParent(DyntaxaTestSettings.Default.TestTaxonId.ToString()) as ViewResult;
                var dropParentViewModel = dropParentResult.ViewData.Model as TaxonDropParentViewModel;


                // Assert
                Assert.IsNotNull(dropParentResult);
                Assert.IsNotNull(dropParentViewModel);

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

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

                Assert.IsNull(dropParentViewModel.SelectedTaxonList);
                Assert.AreEqual(1, dropParentViewModel.TaxonList.Count);
                Assert.AreEqual(refTaxon.Id.ToString(), dropParentViewModel.TaxonId);
                Assert.IsFalse(dropParentViewModel.EnableSaveDeleteParentTaxonButton);
                Assert.AreEqual(refTaxonRevision.Id.ToString(), dropParentViewModel.RevisionId);

                foreach (TaxonParentViewModelHelper helper in dropParentViewModel.TaxonList)
                {
                    Assert.IsNotNull(helper.Category);
                    Assert.IsNotNull(helper.CommonName);
                    Assert.IsNotNull(helper.SortOrder);
                    Assert.IsNotNull(helper.TaxonId);
                    Assert.IsNotNull(helper.ScientificName);
                }
            }
        }
Beispiel #2
0
        public void DropParentPostTest()
        {
            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     = "DropParent";
                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;
                refTaxon.GetNearestParentTaxonRelations(UserContextData).Add(new TaxonRelation()
                {
                    ReplacedInTaxonRevisionEventId = null,
                    CreatedBy      = 1,
                    CreatedDate    = new DateTime(2011),
                    ValidToDate    = new DateTime(2022),
                    IsMainRelation = false,
                    Id             = 55555
                });


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


                var addParentResult = controller.DropParent(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("DropParent", addParentResult.RouteValues["action"]);

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

                // Assert
                Assert.IsNotNull(addParentResult2);

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