Exemplo 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);
        }
Exemplo 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);
 }
Exemplo 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());
 }
Exemplo 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);
 }
Exemplo 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);
        }
Exemplo 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());
 }