This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel.DataAnnotations; | |
using System.Linq; | |
using System.Web; | |
using System.Web.Mvc; | |
using Bongles.WebAPI.Controllers; | |
namespace Bungles.FindDrinks.Models | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Bungles.FindDrinks.Models; | |
using System; | |
using System.Data.Entity; | |
using System.Linq; | |
namespace Blog.MockingWebAPI.Repository | |
{ | |
/// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Blog.MockingWebAPI.Repository; | |
using Bungles.FindDrinks.Models; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Net; | |
using System.Net.Http; | |
using System.Web.Http; | |
namespace Bongles.WebAPI.Controllers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Blog.MockingWebAPI.Repository; | |
using Bungles.FindDrinks.Models; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Net; | |
using System.Net.Http; | |
using System.Web.Http; | |
namespace Bongles.WebAPI.Controllers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Define the mock data | |
using System.Collections.Generic; | |
var data = new List{ | |
new Location { id= 1 , gogId="ChIJ_w0bJLzUf0cRy_s3-sYl0UU", address="Via Zamboni, 16/d, 40126 Bologna, Italia", telephone="051 1889 9835", description=null, | |
geolocation="(44.495439, 11.348128999999972)", name="Lab16", openingHours="Lunedì: 07:00–03:00 | Martedì: 07:00–03:00 | Mercoledì: 07:00–03:00 | Giovedì: 07:00–03:00 | Venerdì: 07:00–03:00 | Sabato: 17:30–03:30 | Domenica: 17:30–03:30", | |
rating=4.4F, website="http://www.lab16.it/", url= "https://plus.google.com/108077084127565302676/about?hl=it-IT" , | |
drinks =new List{ | |
new Drink{ id= 4, description="Drink1", name="Drink1", price=5.00M}, | |
new Drink{ id= 5, description="Drink2", name="Drink2", price=3.50M}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Define the mock type as DbSet<Location> | |
var mockSet = new Mock<DbSet<Location>(); | |
//Define the mock Repository as databaseEf | |
var mockContext = new Mock<databaseEF>(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Define the mock data | |
using System.Collections.Generic; | |
//Bind all data attributes to your mockSe | |
mockSet.As<IQueryable<Location>>().Setup(m => m.Provider).Returns(data.Provider); | |
mockSet.As<IQueryable<Location>>().Setup(m => m.Expression).Returns(data.Expression); | |
mockSet.As<IQueryable<Location>>().Setup(m => m.ElementType).Returns(data.ElementType); | |
mockSet.As<IQueryable<Location>>().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Init the WebAPI service | |
var service = new DrinksController(mockContext.Object); | |
//Check the equality between the returned data and the expected data | |
Assert.AreEqual( "Drink1", service.GetByLocId(data.First().id).First().name); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Bongles.WebAPI.Tests.Controllers | |
{ | |
[TestClass] | |
public class DrinksControllerTests | |
{ | |
[TestMethod] | |
public void GetByIdLocation() | |
{ | |
//Define the mock data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name":"demo", | |
"version":"0.0.0", | |
"main": "index.js" | |
} |