chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
I'm getting strange results that I don't understand. Either of these unit tests will pass when run individually:

[Isolated, TestMethod, Owner("Mark Phillips"), TestCategory("Default Replenishment Information")]
public void UpdateDefaultReplenishmentByStockTypeId_CaseQuantityTooLow_ExpectValidationError()
{
//Arrange
string expectedError = "Case quantity must be 1 or greater.";

Isolate.NonPublic.WhenCalled<ProductReplenishmentData>("StockTypeIdIsValid").IgnoreCall();

ProductReplenishmentDefaults defaults = ProductReplenishmentDefaults.NewReplenishmentItemDefaults();
ProductReplenishmentData productReplenishmentData = ProductReplenishmentData.NewReplenishmentItemForDefaultsList(defaults, true);

//Act
productReplenishmentData.CaseQuantity = 0;

//Assert
Assert.IsFalse(productReplenishmentData.IsValid);
Assert.AreEqual<string>(expectedError, productReplenishmentData.BrokenRulesCollection.ToString().StripErrorCode());
}

[Isolated, TestMethod, Owner("Mark Phillips"), TestCategory("Default Replenishment Information")]
public void UpdateDefaultReplenishmentByStockTypeId_CaseQuantityEdgeValue_ExpectValid()
{
//Arrange
Isolate.NonPublic.WhenCalled<ProductReplenishmentData>("StockTypeIdIsValid").IgnoreCall();

ProductReplenishmentDefaults defaults = ProductReplenishmentDefaults.NewReplenishmentItemDefaults();
ProductReplenishmentData productReplenishmentData = ProductReplenishmentData.NewReplenishmentItemForDefaultsList(defaults, true);

//Act
productReplenishmentData.CaseQuantity = 1;

//Assert
Assert.IsTrue(productReplenishmentData.IsValid);
}

But when run together the second one fails with System.InvalidOperationException: Cannot register property CaseQuantity after containing type (ProductReplenishmentData) has been instantiated.

Both methods have the Isolated attribute, so why would the results be different when run individually versus together?

I am using version 6.0.10.0.

Thanks,
Mark
asked by MarkPhillips7 (3.1k points)

3 Answers

0 votes
Hi Mark,

I can't reproduce the error from the code you posted since I don't have the code under test :(
If it's possible I suggest that you'll send us a small repro of the problem to our support mail:
support at typemock.com
If it is not possible we can do remote desktop session to solve the issue.
answered by ohad (35.5k points)
0 votes
Hi - look, I have no idea if this pertains to your problem, but when I had issues with multiple tests failing (yet individually succeeding), I found I could solve this by having "Isolate.CleanUp()" between tests. For example:
[TestCleanup]
public void Cleanup()
{
    Isolate.CleanUp();
}
answered by xdzgor (3.3k points)
0 votes
Adding the "Isolated" descriptor to the test class worked when I encountered that problem:

[TestClass, Isolated]
public class CollectionsTests
answered by michaelkbarnett (140 points)
...