public void IsEnabled_DikeProfileCollectionSourcePathSet_ReturnTrue() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); assessmentSection.Stub(a => a.ReferenceLine).Return(new ReferenceLine()); mocks.ReplayAll(); var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); var dikeProfiles = new DikeProfileCollection(); dikeProfiles.AddRange(Enumerable.Empty <DikeProfile>(), "some/path"); var context = new DikeProfilesContext(dikeProfiles, failureMechanism, assessmentSection); using (var plugin = new GrassCoverErosionInwardsPlugin()) { UpdateInfo importInfo = GetUpdateInfo(plugin); // Call bool isEnabled = importInfo.IsEnabled(context); // Assert Assert.IsTrue(isEnabled); } mocks.VerifyAll(); }
public void VerifyUpdates_CalculationWithoutOutputs_ReturnsTrue() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); var mainWindow = mocks.Stub <IMainWindow>(); var gui = mocks.Stub <IGui>(); gui.Stub(g => g.MainWindow).Return(mainWindow); mocks.ReplayAll(); using (var plugin = new GrassCoverErosionInwardsPlugin()) { plugin.Gui = gui; var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(new GrassCoverErosionInwardsCalculation()); var dikeProfiles = new DikeProfileCollection(); var context = new DikeProfilesContext(dikeProfiles, failureMechanism, assessmentSection); UpdateInfo updateInfo = GetUpdateInfo(plugin); // Call bool updatesVerified = updateInfo.VerifyUpdates(context); // Assert Assert.IsTrue(updatesVerified); mocks.VerifyAll(); } }
public void CurrentPath_DikeProfileCollectionHasPathSet_ReturnsExpectedPath() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); const string expectedFilePath = "some/path"; var surfaceLines = new DikeProfileCollection(); surfaceLines.AddRange(new[] { DikeProfileTestFactory.CreateDikeProfile() }, expectedFilePath); var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); var context = new DikeProfilesContext(surfaceLines, failureMechanism, assessmentSection); using (var plugin = new GrassCoverErosionInwardsPlugin()) { UpdateInfo updateInfo = GetUpdateInfo(plugin); // Call string currentFilePath = updateInfo.CurrentPath(context); // Assert Assert.AreEqual(expectedFilePath, currentFilePath); mocks.VerifyAll(); } }
public void IsEnabled_ReferenceLineWithGeometry_ReturnTrue() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); assessmentSection.Stub(a => a.ReferenceLine).Return(ReferenceLineTestFactory.CreateReferenceLineWithGeometry()); mocks.ReplayAll(); var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); var context = new DikeProfilesContext(failureMechanism.DikeProfiles, failureMechanism, assessmentSection); using (var plugin = new GrassCoverErosionInwardsPlugin()) { ImportInfo importInfo = GetImportInfo(plugin); // Call bool isEnabled = importInfo.IsEnabled(context); // Assert Assert.IsTrue(isEnabled); } mocks.VerifyAll(); }
public void IsEnabled_DikeProfileCollectionSourcePathNull_ReturnFalse() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); var dikeProfiles = new DikeProfileCollection(); var context = new DikeProfilesContext(dikeProfiles, failureMechanism, assessmentSection); using (var plugin = new GrassCoverErosionInwardsPlugin()) { UpdateInfo importInfo = GetUpdateInfo(plugin); // Call bool isEnabled = importInfo.IsEnabled(context); // Assert Assert.IsFalse(isEnabled); } mocks.VerifyAll(); }
public void ChildNodeObjects_Always_ReturnDikeProfiles() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); DikeProfile dikeProfile1 = DikeProfileTestFactory.CreateDikeProfile(string.Empty, "id1"); DikeProfile dikeProfile2 = DikeProfileTestFactory.CreateDikeProfile(string.Empty, "id2"); var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); failureMechanism.DikeProfiles.AddRange(new[] { dikeProfile1, dikeProfile2 }, "path"); var dikeProfilesContext = new DikeProfilesContext(failureMechanism.DikeProfiles, failureMechanism, assessmentSection); // Call object[] children = info.ChildNodeObjects(dikeProfilesContext); // Assert Assert.AreEqual(2, children.Length); Assert.AreSame(dikeProfile1, children.ElementAt(0)); Assert.AreSame(dikeProfile2, children.ElementAt(1)); mocks.VerifyAll(); }
public void ForeColor_CollectionHasElementsEmpty_ReturnControlText() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); failureMechanism.DikeProfiles.AddRange(new[] { DikeProfileTestFactory.CreateDikeProfile() }, "path"); // Precondition CollectionAssert.IsNotEmpty(failureMechanism.DikeProfiles); var context = new DikeProfilesContext(failureMechanism.DikeProfiles, failureMechanism, assessmentSection); // Call Color color = info.ForeColor(context); // Assert Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), color); mocks.VerifyAll(); }
public void VerifyUpdates_CalculationWithOutputs_AlwaysReturnsExpectedInquiryMessage(bool isActionConfirmed) { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); var mainWindow = mocks.Stub <IMainWindow>(); var gui = mocks.Stub <IGui>(); gui.Stub(g => g.MainWindow).Return(mainWindow); mocks.ReplayAll(); using (var plugin = new GrassCoverErosionInwardsPlugin()) { plugin.Gui = gui; var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(new GrassCoverErosionInwardsCalculation { Output = new TestGrassCoverErosionInwardsOutput() }); var dikeProfiles = new DikeProfileCollection(); var context = new DikeProfilesContext(dikeProfiles, failureMechanism, assessmentSection); UpdateInfo updateInfo = GetUpdateInfo(plugin); string textBoxMessage = null; DialogBoxHandler = (name, wnd) => { var helper = new MessageBoxTester(wnd); textBoxMessage = helper.Text; if (isActionConfirmed) { helper.ClickOk(); } else { helper.ClickCancel(); } }; // Call bool updatesVerified = updateInfo.VerifyUpdates(context); // Assert string expectedInquiryMessage = "Als dijkprofielen wijzigen door het bijwerken, " + "dan worden de resultaten van berekeningen die deze dijkprofielen gebruiken " + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; Assert.AreEqual(expectedInquiryMessage, textBoxMessage); Assert.AreEqual(isActionConfirmed, updatesVerified); mocks.VerifyAll(); } }
public void Constructor_ValidValues_ExpectedValues() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); // Call var context = new DikeProfilesContext(failureMechanism.DikeProfiles, failureMechanism, assessmentSection); // Assert Assert.IsInstanceOf <WrappedObjectContextBase <DikeProfileCollection> >(context); Assert.AreSame(failureMechanism.DikeProfiles, context.WrappedData); Assert.AreSame(failureMechanism, context.ParentFailureMechanism); Assert.AreSame(assessmentSection, context.ParentAssessmentSection); mocks.VerifyAll(); }
public void CreateInstance_WithContext_NewPropertiesWithInputContextAsData() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); var collection = new DikeProfileCollection(); var context = new DikeProfilesContext(collection, failureMechanism, assessmentSection); // Call IObjectProperties objectProperties = info.CreateInstance(context); // Assert Assert.IsInstanceOf <DikeProfileCollectionProperties>(objectProperties); Assert.AreSame(collection, objectProperties.Data); mocks.VerifyAll(); }
public void ForeColor_CollectionIsEmpty_ReturnGrayText() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); // Precondition CollectionAssert.IsEmpty(failureMechanism.DikeProfiles); var context = new DikeProfilesContext(failureMechanism.DikeProfiles, failureMechanism, assessmentSection); // Call Color color = info.ForeColor(context); // Assert Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), color); mocks.VerifyAll(); }
public void CreateFileImporter_Always_ReturnsFileImporter() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); assessmentSection.Stub(a => a.ReferenceLine).Return(new ReferenceLine()); mocks.ReplayAll(); var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); var context = new DikeProfilesContext(failureMechanism.DikeProfiles, failureMechanism, assessmentSection); using (var plugin = new GrassCoverErosionInwardsPlugin()) { UpdateInfo updateInfo = GetUpdateInfo(plugin); // Call IFileImporter importer = updateInfo.CreateFileImporter(context, string.Empty); // Assert Assert.IsInstanceOf <DikeProfilesImporter>(importer); mocks.VerifyAll(); } }