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
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
Hello,

I tried to write an Unit Test for an litte self written ORM.
For short
public sealed class Authority : BaseEntity<EntityIdKey>
{
public short AuthorityNumber { get; set; }
}

public sealed class Receivable : BaseEntity<EntityIdKey>
{
public long? AuthorityId { get; set; }
public Authority LinkedAuthority { get; set; }
}

Its given that when AutorityId is not null LinkedAutority holts the Authority object.
However the Test faild with an Typemock Exception
The Test:
[TestMethod]
      public void SortReceivablesByFederalTradeAssociationRulingTypeTest2()
      {
         List<PaymentPriority> priorities = new List<PaymentPriority> {new PaymentPriority(7L) {FederalEconomicChamberId = 1L, FederalTradeAssociationRulingType = FederalTradeAssociationRulingType.ExtraBaseCharge, IgnoreProcessingCode = true, PreferOldYears = false, PreferProcessingCode = true, Priority = 4, ReceivableType = ReceivableType.ChamberCharge}, new PaymentPriority(1L) {FederalEconomicChamberId = 1L, FederalTradeAssociationRulingType = null, IgnoreProcessingCode = true, PreferOldYears = false, PreferProcessingCode = true, Priority = 1, ReceivableType = ReceivableType.ChamberCharge}, new PaymentPriority(4L) {FederalEconomicChamberId = 1L, FederalTradeAssociationRulingType = FederalTradeAssociationRulingType.BaseCharge, IgnoreProcessingCode = true, PreferOldYears = false, PreferProcessingCode = true, Priority = 1, ReceivableType = ReceivableType.ChamberCharge}, new PaymentPriority(5L) {FederalEconomicChamberId = 1L, FederalTradeAssociationRulingType = FederalTradeAssociationRulingType.ExtraCharge, IgnoreProcessingCode = true, PreferOldYears = false, PreferProcessingCode = true, Priority = 2, ReceivableType = ReceivableType.ChamberCharge}, new PaymentPriority(6L) {FederalEconomicChamberId = 1L, FederalTradeAssociationRulingType = FederalTradeAssociationRulingType.SpecialCharge, IgnoreProcessingCode = true, PreferOldYears = false, PreferProcessingCode = true, Priority = 3, ReceivableType = ReceivableType.ChamberCharge}, new PaymentPriority(2L) {FederalEconomicChamberId = 1L, FederalTradeAssociationRulingType = null, IgnoreProcessingCode = true, PreferOldYears = false, PreferProcessingCode = true, Priority = 2, ReceivableType = ReceivableType.CollectionExpenses}, new PaymentPriority(3L) {FederalEconomicChamberId = 1L, FederalTradeAssociationRulingType = null, IgnoreProcessingCode = true, PreferOldYears = false, PreferProcessingCode = true, Priority = 3, ReceivableType = ReceivableType.LegalCharge}};
         Receivable fakeReceivable1 = Isolate.Fake.Instance<Receivable>();
         Receivable fakeReceivable2 = Isolate.Fake.Instance<Receivable>();
         Receivable fakeReceivable3 = Isolate.Fake.Instance<Receivable>();
         Receivable fakeReceivable4 = Isolate.Fake.Instance<Receivable>();
         Receivable fakeReceivable5 = Isolate.Fake.Instance<Receivable>();
         List<Receivable> receivablesToSort = new List<Receivable> {fakeReceivable1, fakeReceivable2, fakeReceivable3, fakeReceivable4, fakeReceivable5};
         Isolate.WhenCalled(() => fakeReceivable1.LinkedFederalTradeAssociationRuling.Load()).IgnoreCall();
         Isolate.WhenCalled(() => fakeReceivable2.LinkedFederalTradeAssociationRuling.Load()).IgnoreCall();
         Isolate.WhenCalled(() => fakeReceivable3.LinkedFederalTradeAssociationRuling.Load()).IgnoreCall();
         Isolate.WhenCalled(() => fakeReceivable4.LinkedFederalTradeAssociationRuling.Load()).IgnoreCall();
         Isolate.WhenCalled(() => fakeReceivable5.LinkedFederalTradeAssociationRuling.Load()).IgnoreCall();
         Isolate.WhenCalled(() => fakeReceivable1.LinkedFederalTradeAssociationRuling.State).WillReturn(EntityState.Full);
         Isolate.WhenCalled(() => fakeReceivable2.LinkedFederalTradeAssociationRuling.State).WillReturn(EntityState.Full);
         Isolate.WhenCalled(() => fakeReceivable3.LinkedFederalTradeAssociationRuling.State).WillReturn(EntityState.Full);
         Isolate.WhenCalled(() => fakeReceivable4.LinkedFederalTradeAssociationRuling.State).WillReturn(EntityState.Full);
         Isolate.WhenCalled(() => fakeReceivable5.LinkedFederalTradeAssociationRuling.State).WillReturn(EntityState.Full);
         Isolate.WhenCalled(() => fakeReceivable1.LinkedFederalTradeAssociationRuling.FederalTradeAssociationRulingType).WillReturn(FederalTradeAssociationRulingType.BaseCharge);
         Isolate.WhenCalled(() => fakeReceivable2.LinkedFederalTradeAssociationRuling.FederalTradeAssociationRulingType).WillReturn(FederalTradeAssociationRulingType.BaseCharge);
         Isolate.WhenCalled(() => fakeReceivable3.LinkedFederalTradeAssociationRuling.FederalTradeAssociationRulingType).WillReturn(FederalTradeAssociationRulingType.BaseCharge);
         Isolate.WhenCalled(() => fakeReceivable4.LinkedFederalTradeAssociationRuling.FederalTradeAssociationRulingType).WillReturn(FederalTradeAssociationRulingType.BaseCharge);
         Isolate.WhenCalled(() => fakeReceivable5.LinkedFederalTradeAssociationRuling.FederalTradeAssociationRulingType).WillReturn(FederalTradeAssociationRulingType.BaseCharge);
         Isolate.WhenCalled(() => fakeReceivable1.LinkedFederalTradeAssociationRuling.Number).WillReturn(new NotNullable<string>("101"));
         Isolate.WhenCalled(() => fakeReceivable2.LinkedFederalTradeAssociationRuling.Number).WillReturn(new NotNullable<string>("101"));
         Isolate.WhenCalled(() => fakeReceivable3.LinkedFederalTradeAssociationRuling.Number).WillReturn(new NotNullable<string>("101"));
         Isolate.WhenCalled(() => fakeReceivable4.LinkedFederalTradeAssociationRuling.Number).WillReturn(new NotNullable<string>("102"));
         Isolate.WhenCalled(() => fakeReceivable5.LinkedFederalTradeAssociationRuling.Number).WillReturn(new NotNullable<string>("102"));
         Isolate.WhenCalled(() => fakeReceivable1.LinkedAuthority.Load()).IgnoreCall();
         Isolate.WhenCalled(() => fakeReceivable2.
asked by swtrse (4k points)

4 Answers

0 votes
I added a new UnitTest. Now the error is gone.

Very strange. Just to be complete the Isolated Attribute is defined at class level (If someone is suggestint that it is missing).
answered by swtrse (4k points)
0 votes
Hi,

Unfortunately it's difficult to tell, your text code, however large, should be correct. If this problem persists, could you please send a repro solution to support at typemock.com?

I would highly recommend, for readability and test correctness to refactor your code, at least place common initialization into a separate mehtod.
answered by igal (5.7k points)
0 votes
The error is back again.
I will extract the specific parts end send you an solution
answered by swtrse (4k points)
0 votes
While making the solution to send.
I realized what the problem is.
The Entities I am using are located inside some dlls.
This dlls got a new Version.
Since each project referenced the assemblys with Specific Version = false this is not a problem.
However one testproject referenced the assemblys with Specific Version = true so during the unit tests in this specific testproject typemock looks at an old Version(where the getter realy do not exists).
answered by swtrse (4k points)
...