本文整理汇总了C#中Moq.Mock.Setup方法的典型用法代码示例。如果您正苦于以下问题:C# Moq.Mock.Setup方法的具体用法?C# Moq.Mock.Setup怎么用?C# Moq.Mock.Setup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Moq.Mock
的用法示例。
在下文中一共展示了Moq.Mock.Setup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSimple_2
public void TestSimple_2()
{
var facts = new List<NullableFact>();
facts.Add(new NullableFact() { ProductId = null, GeographyId = null, SalesComponentId = null, TimeId = 1, Value = 100 });
var products = new Moq.Mock<IHierarchy>();
var geographies = new Moq.Mock<IHierarchy>();
var causals = new Moq.Mock<IHierarchy>();
var periods = new Moq.Mock<IHierarchy>();
Expression<Func<IHierarchy, IEnumerable<short>>> anyInt = p => p.GetParents(Moq.It.IsAny<short>());
var result = new List<short> { 1 };
products.Setup(anyInt).Returns(result);
geographies.Setup(anyInt).Returns(result);
causals.Setup(anyInt).Returns(result);
periods.Setup(anyInt).Returns(result);
Expression<Func<IHierarchy, bool>> allRelationships = p => p.RelationExists(Moq.It.IsAny<short>(), Moq.It.IsAny<short>());
products.Setup(allRelationships).Returns(true);
geographies.Setup(allRelationships).Returns(true);
causals.Setup(allRelationships).Returns(true);
periods.Setup(allRelationships).Returns(true);
//, Hierarchy products, Hierarchy geographies, Hierarchy causals, Hierarchy periods
var lookup = new FactLookup(facts, products.Object, geographies.Object, causals.Object, periods.Object);
Assert.AreEqual(100, lookup.GetParent(0, 0, 0, 1));
Assert.AreEqual(100, lookup.GetParent(1, 1, 1, 1));
Assert.AreEqual(100, lookup.GetParent(2, 2, 2, 1));
}
示例2: CreateCartController
ShoppingCart.Web.Mvc.Controllers.CartController CreateCartController()
{
var mock = new Moq.Mock<ControllerContext>();
var cartRepository = new Services.MockCartRepository();
var cartService = new ShoppingCart.Web.Mvc.Services.CartService(cartRepository);
var product = new Moq.Mock<Model.IProduct>();
product.Setup(i => i.Code).Returns("xxx");
product.Setup(i => i.Packaging).Returns(1);
product.Setup(i => i.SaleUnitValue).Returns(1);
product.Setup(i => i.Title).Returns("product 1");
var catalogService = new Moq.Mock<Mvc.Services.ICatalogService>();
catalogService.Setup(i => i.GetProductByCode("xxx")).Returns(product.Object);
catalogService.Setup(i => i.GetPriceByProduct(product.Object)).Returns(new ShoppingCart.Web.Mvc.Model.Price(10.0, 0.196));
var controller = new ShoppingCart.Web.Mvc.Controllers.CartController(
cartService,
catalogService.Object);
controller.ControllerContext = mock.Object;
return controller;
}
示例3: GetAdPicturesFromModel_2Pictures_FetchThemFromRepoAndSetFirstAsMainImage
public void GetAdPicturesFromModel_2Pictures_FetchThemFromRepoAndSetFirstAsMainImage()
{
// Given
BaseAd ad = new Ad();
String images = "b9da8b1e-aa77-401b-84e0-a1290130b7b7;b9da8b1e-aa77-401b-84e0-a1290130b999;";
AdImage img1 = new AdImage() { Id = Guid.Parse("b9da8b1e-aa77-401b-84e0-a1290130b7b7") };
AdImage img2 = new AdImage() { Id = Guid.Parse("b9da8b1e-aa77-401b-84e0-a1290130b999") };
var repoMock = new Moq.Mock<IRepository>();
repoMock.Setup(x => x.Get<AdImage>(Guid.Parse("b9da8b1e-aa77-401b-84e0-a1290130b7b7"))).Returns(img1);
repoMock.Setup(x => x.Get<AdImage>(Guid.Parse("b9da8b1e-aa77-401b-84e0-a1290130b999"))).Returns(img2);
AdServices service = new AdServices(null, repoMock.Object, null);
// When
BaseAd result = service.GetAdPicturesFromModel(ad, images);
// Then
Assert.AreEqual(ad, result);
Assert.AreEqual(2, ad.Images.Count);
Assert.AreEqual("b9da8b1e-aa77-401b-84e0-a1290130b7b7", ad.Images[0].Id.ToString());
Assert.AreEqual(ad, ad.Images[0].BaseAd);
Assert.IsTrue(ad.Images[0].IsPrimary);
Assert.AreEqual("b9da8b1e-aa77-401b-84e0-a1290130b999", ad.Images[1].Id.ToString());
Assert.AreEqual(ad, ad.Images[1].BaseAd);
Assert.IsFalse(ad.Images[1].IsPrimary);
}
示例4: ConcreteFactLookup_GlobalFact
public void ConcreteFactLookup_GlobalFact()
{
var facts = new List<ConcreteFact>();
facts.Add(new ConcreteFact() { ProductId = 2, GeographyId = 2, SalesComponentId = 2, TimeId = 1, Value = 100 });
facts.Add(new ConcreteFact() { ProductId = 3, GeographyId = 3, SalesComponentId = 3, TimeId = 1, Value = 100 });
var products = new Moq.Mock<IHierarchy>();
var geographies = new Moq.Mock<IHierarchy>();
var causals = new Moq.Mock<IHierarchy>();
var periods = new Moq.Mock<IHierarchy>();
Expression<Func<IHierarchy, IEnumerable<short>>> anyInt = p => p.GetChildren(Moq.It.IsAny<short>());
var result = new List<short> { 2, 3 };
products.Setup(anyInt).Returns(result);
geographies.Setup(anyInt).Returns(result);
causals.Setup(anyInt).Returns(result);
periods.Setup(anyInt).Returns(result);
Expression<Func<IHierarchy, bool>> relation = h => h.RelationExists(Moq.It.IsAny<short>(), Moq.It.IsAny<short>());
products.Setup(relation).Returns(true);
geographies.Setup(relation).Returns(true);
causals.Setup(relation).Returns(true);
periods.Setup(relation).Returns(true);
//, Hierarchy products, Hierarchy geographies, Hierarchy causals, Hierarchy periods
var lookup = new ConcreteFactLookup(facts, products.Object, geographies.Object, causals.Object, periods.Object);
Assert.AreEqual(200, lookup.SumChildren(1, 1, 1, 1));
}
示例5: GetAdDetails_AdExists_GetAdFromRepoAndReturnAdModel
public void GetAdDetails_AdExists_GetAdFromRepoAndReturnAdModel()
{
// Given
Ad ad = new Ad() { Id = 17 };
ad.CreationDate = new DateTime(2012, 02, 18);
ad.CreatedBy = new User { Firstname = "Michel" };
ad.City = new City { Label = "Ville" };
var repoMock = new Moq.Mock<IRepository>();
repoMock.Setup(x => x.Get<BaseAd>(17)).Returns(ad as BaseAd);
var adRepoMock = new Moq.Mock<IAdRepository>();
adRepoMock.Setup(r => r.GetAdType(17)).Returns(AdTypeEnum.Ad);
adRepoMock.Setup(r => r.GetAdById<Ad>(17)).Returns(ad);
var helperMock = new Moq.Mock<IHelperService>();
helperMock.Setup(s => s.GetCurrentDateTime()).Returns(new DateTime(2012, 02, 20));
AdDetailsServices service = new AdDetailsServices(adRepoMock.Object, helperMock.Object);
// When
AdDetailsModel actual = service.GetAdDetails(17);
// Then
Assert.AreEqual(17, actual.AdId);
}
示例6: content_type
public void content_type(string extension, string mimeType)
{
var fileInfo = new Moq.Mock<IFileInfo>();
fileInfo.Setup(x => x.Extension).Returns(extension);
fileInfo.Setup(x => x.OpenRead()).Returns(StreamWith("<this doesn't matter>"));
ResponseFile = fileInfo.Object;
WithResponseFrom("http://localhost:8080", response => {
Verify.That(() => response.ContentType == mimeType);
});
}
示例7: EmptyImageReturnsEmptyPalette
public void EmptyImageReturnsEmptyPalette()
{
var image = new Moq.Mock<IImage>();
image.Setup(x => x.Height).Returns(0);
image.Setup(x => x.Width).Returns(0);
var p = new PercentagePaletteInventory
{
Image = image.Object
};
Assert.AreEqual(0,p.Items.Count);
}
示例8: Init
public void Init()
{
var lstValid = SearchResultGenerator();
var lstReports = ReportListGenerator();
var lstUsers = UserListGenerator();
var y = new Moq.Mock<IReportHubDataRepository>();
y.Setup(x => x.Search("validsearch")).Returns(lstValid);
y.Setup(x => x.TopReports(5)).Returns(lstReports.AsEnumerable());
y.Setup(x => x.TopUsers(5)).Returns(lstUsers.AsEnumerable());
rhs = new ReportHubService(y.Object);
}
示例9: Rename
/// <summary>
/// renaming helper method for mocking IMatrixData
/// </summary>
/// <param name="colnames"></param>
/// <param name="pattern"></param>
/// <param name="replacement"></param>
private static void Rename(List<string> colnames, string pattern, string replacement)
{
var renamer = new RenameColumnsRegexp();
var matrix = new Moq.Mock<IMatrixData>();
matrix.Setup(m => m.ColumnCount).Returns(colnames.Count);
matrix.Setup(m => m.ColumnNames).Returns(colnames);
string err = "";
var param = renamer.GetParameters(matrix.Object, ref err);
param.GetParam<Tuple<Regex, string>>("Regex").Value = Tuple.Create(new Regex(pattern), replacement);
IMatrixData[] supplTables = null;
IDocumentData[] documents = null;
renamer.ProcessData(matrix.Object, param, ref supplTables, ref documents, null);
}
示例10: ShouldGetAllLogFiles
public void ShouldGetAllLogFiles()
{
var fileSystem = new Moq.Mock<IFileSystem>();
var logFiles = new[] { @"C:\Path\backup-1234567890.csv" };
var nonLogFiles = new[] { @"C:\Path\no-match.csv" };
fileSystem.Setup(x => x.GetCommonApplicationDataPath()).Returns(@"C:\Path");
fileSystem.Setup(x => x.GetFiles(@"C:\Path\cache\logs")).Returns(logFiles.Union(nonLogFiles));
var target = new JungleDiskLogFilesProvider(fileSystem.Object, new AutomaticLogFilePath(fileSystem.Object));
var result = target.GetAllLogFiles();
result.Should().Have.SameSequenceAs(logFiles);
}
示例11: GetOutboundUrl
private string GetOutboundUrl(object routeValues)
{
RouteCollection routes = new RouteCollection();
RouteConfig.RegisterRoutes(routes);
var mockHttpContext = new Moq.Mock<HttpContextBase>();
var mockRequest = new Moq.Mock<HttpRequestBase>();
var fakeResponse = new FakeResponse();
mockHttpContext.Setup(x => x.Request).Returns(mockRequest.Object);
mockHttpContext.Setup(x => x.Response).Returns(fakeResponse);
mockRequest.Setup(x => x.ApplicationPath).Returns("/");
var ctx = new RequestContext(mockHttpContext.Object, new RouteData());
return routes.GetVirtualPath(ctx, new RouteValueDictionary(routeValues)).VirtualPath;
}
示例12: content_matches
public void content_matches()
{
var message = "Hello World!";
var fileInfo = new Moq.Mock<IFileInfo>();
fileInfo.Setup(x => x.Extension).Returns(".bin");
fileInfo.Setup(x => x.OpenRead()).Returns(StreamWith(message));
ResponseFile = fileInfo.Object;
WithResponseFrom("http://localhost:8080", response => {
Verify.That(() => response.ContentLength == message.Length);
using(var reader = new StreamReader(response.GetResponseStream()))
Verify.That(() => reader.ReadToEnd() == message);
});
}
示例13: RedImageReturnsRedPalette
public void RedImageReturnsRedPalette()
{
var image = new Moq.Mock<IImage>();
image.Setup(x => x.Width).Returns(1);
image.Setup(x => x.Height).Returns(1);
image.Setup(x => x.GetPixel(0,0)).Returns(Color.Red);
var p = new PercentagePaletteInventory
{
Image = image.Object
};
Assert.IsTrue(Math.Abs(p.Items[Color.Red] - 1) < Epsilon);
}
示例14: ContextMocks
public ContextMocks(Controller onController)
{
HttpContext = new Moq.Mock<HttpContextBase>();
Request = new Moq.Mock<HttpRequestBase>();
Response = new Moq.Mock<HttpResponseBase>();
HttpContext.Setup(x => x.Request).Returns(Request.Object);
HttpContext.Setup(x => x.Response).Returns(Response.Object);
HttpContext.Setup(x => x.Session).Returns(new FakeSessionState());
Request.Setup(x => x.Cookies).Returns(new HttpCookieCollection());
Response.Setup(x => x.Cookies).Returns(new HttpCookieCollection());
Request.Setup(x => x.QueryString).Returns(new NameValueCollection());
Request.Setup(x => x.Form).Returns(new NameValueCollection());
RequestContext requestContext = new RequestContext(HttpContext.Object, new RouteData());
onController.ControllerContext = new ControllerContext(requestContext, onController);
}
示例15: tewwet
public void tewwet()
{
var productRepository = new Moq.Mock<IProductRepository>();
productRepository.Setup(x => x.Get())
.Returns(new[]
{
new Product()
{
ID = 1,
Title = "iPad",
Description = "Fruit based tablet",
UnitPrice = 450
},
new Product()
{
ID = 2,
Title = "iPhone",
Description = "Fruit based phone",
UnitPrice = 500
}
});
var homeController = new HomeController(productRepository.Object);
var result = homeController.Index() as ViewResult;
Assert.NotNull(result.Model);
}