Ejemplo n.º 1
0
        public PasswordChangeStatus ChangePasswordTest(string newPassword)
        {
            // Arrange
            MockPanoptoDBDataContext mockedPanoptoDBDataContext = new MockPanoptoDBDataContext();
            DemoClass classUnderTest = new DemoClass(); // or new ExampleClass(mockedPanoptoDBDataContext);

            // Act, method under test
            PasswordChangeStatus result = classUnderTest.ChangePassword(mockedPanoptoDBDataContext, newPassword);

            // Assert
            // Expect SetPassword to be called 1 time only when result was a success
            int calledTimesExpected = (result == PasswordChangeStatus.Success) ? 1 : 0;

            Assert.That(mockedPanoptoDBDataContext.SubmitChanges_WasCalled, Is.EqualTo(calledTimesExpected),
                        "SetPassword method was called {0} times!", mockedPanoptoDBDataContext.SubmitChanges_WasCalled);

            // Test case will assert based on ExpectedResult
            return(result);
        }
Ejemplo n.º 2
0
        public PasswordChangeStatus ChangePasswordTest_WithMoq(string newPassword)
        {
            // Arrange
            Mock <IPanoptoDBDataContext> mockedPanoptoDBDataContext = new Mock <IPanoptoDBDataContext>();

            // Setup order matters when multiple matches possible
            mockedPanoptoDBDataContext.Setup(db => db.PasswordHistoryMatches(It.IsAny <string>(), It.IsAny <int>())).Returns(false);
            mockedPanoptoDBDataContext.Setup(db => db.PasswordHistoryMatches(HistoryPassword, It.IsAny <int>())).Returns(true);
            mockedPanoptoDBDataContext.Setup(db => db.SetPassword(It.IsAny <string>()));
            mockedPanoptoDBDataContext.Setup(db => db.SubmitChanges());
            DemoClass classUnderTest = new DemoClass(); // or new ExampleClass(mockedPanoptoDBDataContext);

            // Act, method under test
            PasswordChangeStatus result = classUnderTest.ChangePassword(mockedPanoptoDBDataContext.Object, newPassword);

            // Assert
            // Expect SetPassword to be called 1 time only when result was a success
            int calledTimesExpected = (result == PasswordChangeStatus.Success) ? 1 : 0;

            mockedPanoptoDBDataContext.Verify(db => db.SubmitChanges(), Times.Exactly(calledTimesExpected));

            // Test case will assert based on ExpectedResult
            return(result);
        }