Beispiel #1
0
 public void CallToServiceOnlyOnce()
 {
     thingCache.Get(thingId1);
     thingCache.Get(thingId1);
     A.CallTo(() => thingService.TryRead(A <string> .Ignored, out tempThing))
     .MustHaveHappened(Repeated.Exactly.Once);
 }
Beispiel #2
0
        public void Get_CallsService_WhenCalledOneTime()
        {
            var th1 = thingCache.Get(thingId1);

            A.CallTo(() => thingService.TryRead(thingId1, out th1)).MustHaveHappened(1, Times.Exactly);
            th1.Should().Be(thing1);
        }
Beispiel #3
0
 public void TryReadFromEmptyCache_ShouldReturnNull()
 {
     thingCache.Get(thingId1)
     .Should().BeNull();
     A.CallTo(() => thingService.TryRead(thingId1, out thing1))
     .MustHaveHappenedOnceExactly();
 }
Beispiel #4
0
        public void CallThingServiceOnce_OnFirstGet()
        {
            thingCache.Get(thingId1);

            Thing _ = null;

            A.CallTo(() => thingService.TryRead(thingId1, out _)).MustHaveHappenedOnceExactly();
        }
Beispiel #5
0
 public void SetUp()
 {
     thingService = A.Fake <IThingService>();
     A.CallTo(() => thingService.TryRead(thingId1, out thing1)).Returns(true);
     A.CallTo(() => thingService.TryRead(thingId2, out thing2)).Returns(true);
     A.CallTo(() => thingService.TryRead(thingIdNotExisted, out thing3)).Returns(false);
     thingCache = new ThingCache(thingService);
 }
Beispiel #6
0
        public void AskThingAndReturnIt()
        {
            A.CallTo(() => thingService.TryRead(thingId1, out thing1))
            .Returns(true);

            var actualThing = thingCache.Get(thingId1);

            Assert.AreEqual(thingId1, actualThing.ThingId);
        }
Beispiel #7
0
        public void TestCanReadShouldCallOnlyOnce()
        {
            var firstItem  = cache.Get(thingKey2);
            var secondItem = cache.Get(thingKey2);

            Assert.That(firstItem == secondItem);
            Assert.That(firstItem == thing2);
            A.CallTo(() => service.TryRead(thingKey2, out thing2)).MustHaveHappenedOnceExactly();
            A.CallTo(() => service.TryRead(A <string> .Ignored, out thing2)).MustHaveHappenedOnceExactly();
        }
Beispiel #8
0
 public void Configure()
 {
     service = A.Fake <IThingService>();
     cache   = new ThingCache(service);
     A.CallTo(() => service.TryRead(A <string> .Ignored, out thing1)).Returns(false);
     A.CallTo(() => service.TryRead(thingKey1, out thing1))
     .Returns(true);
     A.CallTo(() => service.TryRead(thingKey2, out thing2))
     .Returns(true);
 }
Beispiel #9
0
        public void ReturnsNull_WhenIdNotExists()
        {
            Thing thing;

            A.CallTo(() => thingService.TryRead("1", out thing)).Returns(false);

            thingCache.Get("1").Should().BeNull();
        }
Beispiel #10
0
        public void SetUp()
        {
            thingService = A.Fake <IThingService>();
            thingCache   = new ThingCache(thingService);
            Thing thing;

            A.CallTo(() => thingService.TryRead(A <string> .Ignored, out thing)).Returns(false);
            A.CallTo(() => thingService.TryRead(thingId1, out thing)).Returns(true)
            .AssignsOutAndRefParameters(thing1);

            A.CallTo(() => thingService.TryRead(thingId2, out thing)).Returns(true)
            .AssignsOutAndRefParameters(thing2);;
        }
Beispiel #11
0
        public void Get_NoneExistingObject_ReturnsNull()
        {
            thingCache.Get(thingId1)
            .Should().BeNull();

            A.CallTo(() => thingService.TryRead(thingId1, out thing1))
            .MustHaveHappened();
        }
Beispiel #12
0
        public void SetUp()
        {
            thingService = A.Fake <IThingService>();
            thingCache   = new ThingCache(thingService);

            Thing _ = null;

            A.CallTo(() => thingService.TryRead(thingId1, out _))
            .Returns(true)
            .AssignsOutAndRefParameters(thing1);

            A.CallTo(() => thingService.TryRead(thingId2, out _))
            .Returns(true)
            .AssignsOutAndRefParameters(thing2);
        }
Beispiel #13
0
        public void SingleThingGetting()
        {
            A.CallTo(() => thingService.TryRead(thingId1, out thing1)).Returns(true);
            Assert.AreEqual(thing1, thingCache.Get(thingId1));

            Thing value;

            A.CallTo(() => thingService.TryRead(A <string> .Ignored, out value)).MustHaveHappened();
        }
Beispiel #14
0
        public void TryGetExistedElement()
        {
            var value = new Thing(thingId1);

            A.CallTo(() => thingService.TryRead(thingId1, out value))
            .Returns(true);

            var actual = thingCache.Get(thingId1);

            actual.Should().Be(value);
        }
Beispiel #15
0
 public Thing Get(string thingId)
 {
     if (dictionary.TryGetValue(thingId, out var thing))
     {
         return(thing);
     }
     if (thingService.TryRead(thingId, out thing))
     {
         dictionary[thingId] = thing;
         return(thing);
     }
     return(null);
 }
Beispiel #16
0
        public void ReturnCorrectThing_TakeItFirstTimeFromService()
        {
            A.CallTo(() => thingService.TryRead(thingId1, out thing1)).Returns(true);

            thingCache.Get(thingId1).Should().Be(thing1);
            A.CallTo(() => thingService.TryRead(thingId1, out thing1)).MustHaveHappened();
        }
Beispiel #17
0
        public void CheckCallTryRead()
        {
            var th = thingCache.Get(thingId1);

            A.CallTo(() => thingService.TryRead(thingId1, out thing1)).WithAnyArguments().MustHaveHappenedOnceExactly();
        }
Beispiel #18
0
 public void Cache_Should_CallService_When_NoKeyFoundInside()
 {
     thingCache.Get(thingId1);
     A.CallTo(() => thingService.TryRead(thingId1, out thing1)).MustHaveHappened();
 }
Beispiel #19
0
        public void TryRead_ExecutedOnce_AfterFirstGetSameThing()
        {
            Thing _;

            thingCache.Get(thingId1).Should().BeNull();
            A.CallTo(() => thingService.TryRead(thingId1, out _))
            .MustHaveHappened(Repeated.Exactly.Once);
        }
Beispiel #20
0
 public void ThingCache_Get_MethodCallingHappened()
 {
     thingCache.Get(thingId1);
     A.CallTo(() => thingService.TryRead(thingId1, out thing1)).MustHaveHappenedOnceExactly();
 }