Esempio n. 1
0
        public void ShouldReturnItJsonSerialized()
        {
            var service = new Mock<IWidgetService>();
            service.Setup(s => s.GetNumberFromCache()).Throws(new KeyNotFoundException());
            var widget = new Widget(service.Object);
            widget.Init();

            var result = widget.GetSerializedAsString();
            Assert.IsNotNull(result);
        }
Esempio n. 2
0
 public void ShouldOnlyCallCache()
 {
     var service = new Mock<IWidgetService>();
     service.Setup(s => s.GetNumberFromCache())
         .Returns(new CachedNumber());
     var widget = new Widget(service.Object);
     widget.Init();
     service.Verify(s => s.GetNumberFromCache());
     service.Verify(s => s.GetNumber(), Times.Never);
 }
Esempio n. 3
0
 public void ShouldCallCacheBeforeUpdating()
 {
     var service = new Mock<IWidgetService>();
     service.Setup(s => s.GetNumberFromCache())
         .Returns(new CachedNumber());
     var widget = new Widget(service.Object);
     widget.Init();
     service.Verify(s => s.GetNumberFromCache());
     widget.Update();
     service.Verify(s => s.GetNumber());
 }
Esempio n. 4
0
 public void UpdateTimeShouldBeUpdatedIfGetNumberIsSuccesful()
 {
     var service = new Mock<IWidgetService>();
     service.Setup(s => s.GetNumberFromCache())
         .Returns(new CachedNumber() { Value = 10, UpdatedAt = new DateTime(2012,01,01) });
     var widget = new Widget(service.Object);
     widget.Init();
     var updateDate = widget.UpdatedAt;
     widget.Update();
     service.Verify(s => s.GetNumber());
     var updateDateAfterUpdate = widget.UpdatedAt;
     Assert.AreNotEqual(updateDate, updateDateAfterUpdate);
 }
Esempio n. 5
0
        public void ShouldHaveSelectedFields()
        {
            var service = new Mock<IWidgetService>();
            service.Setup(s => s.GetNumberFromCache())
                .Returns(new CachedNumber());
            var widget = new Widget(service.Object);
            widget.Init();

            widget.AddField("URL", string.Empty);
            widget.AddField("Options", "Likes", "People talking about");

            var fields = widget.GetFields();
            Assert.AreEqual(2, fields.Count);
        }
Esempio n. 6
0
 public void UpdateTimeShouldHandleExceptionFromCache()
 {
     var service = new Mock<IWidgetService>();
     service.Setup(s => s.GetNumberFromCache()).Throws(new KeyNotFoundException());
     var widget = new Widget(service.Object);
     widget.Init();
     service.Verify(s => s.GetNumberFromCache());
     widget.Update();
     service.Verify(s => s.GetNumberFromCache());
 }