Blog

My blog serves as a way for me to post solutions to problems I solve at work or during the long hours of freelance work.

MSTest Unit Tests

[TestMethod]
public void Debit_WithValidAmount_UpdatesBalance()
{
    // arrange
    double beginningBalance = 11.99;
    double debitAmount = 4.55;
    double expected = 7.44;
    BankAccount account = new BankAccount("Mr. Bryan Walton", beginningBalance);

    // act
    account.Debit(debitAmount);

    // assert
    double actual = account.Balance;
    Assert.AreEqual(expected, actual, 0.001, "Account not debited correctly");
}

[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void Debit_WhenAmountIsLessThanZero_ShouldThrowArgumentOutOfRange()
{
    // arrange
    double beginningBalance = 11.99;
    double debitAmount = -100.00;
    BankAccount account = new BankAccount("Mr. Bryan Walton", beginningBalance);

    // act
    account.Debit(debitAmount);

    // assert is handled by ExpectedException
}

[TestMethod(), TestCategory("Integration")]
public void TestSurgeonInsertion()
{
    using (TransactionScope scope = new TransactionScope())
    {
        int beforeCount = 0;
        int afterCount = 0;

        RoboticsSurgeryEntities roboticsDB = new RoboticsSurgeryEntities();
        beforeCount = roboticsDB.Surgeons.ToList().Count;

        SurgeryController_Accessor target = new SurgeryController_Accessor();
        List<String> newSurgeons = new List<String> { "Not Selected", "Dr. Bob" };

        target.SaveMissingSurgeons(newSurgeons);

        afterCount = roboticsDB.Surgeons.ToList().Count;

        Assert.AreEqual(++beforeCount, afterCount, "Should have had one more surgeon entered into DB");
    }
}

 Intergration test -

        [TestMethod()]
        public void GetSurgeryInfoForPPMC()
        {
            SurgerySchedule target = new SurgerySchedule();
            DateTime dateOfService = new DateTime(2010, 2, 12);

            List<SurgeryInformation> actual;
            actual = target.GetSurgeryInfo(dateOfService, Facility.PPMC);

            Assert.AreEqual(87, actual.Count);
        }

 

 

 


RecentPosts