This file contains 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
[Fact] | |
public void TrackAllPropertiesWithSetupAllProperties() | |
{ | |
var mock = new Mock<IPropertyManager>(); | |
//mock.SetupProperty(m => m.FirstName); | |
//Comment this and uncomment SetupProperty, the assertion fails | |
mock.SetupAllProperties(); |
This file contains 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
[Fact] | |
public void Verify() | |
{ | |
var mock = new Mock<IPropertyManager>(); | |
var nameUser = new PropertyManagerConsumer(mock.Object); | |
nameUser.ChangeRemoteName("My dear old wig"); | |
//we are verifying that ChangeRemoteName sends the correct string to MutateFirstName | |
mock.Verify(m => m.MutateFirstName(It.Is<string>(a => a == "My dear old wig")), Times.Once); |
This file contains 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
public List<SelectListItem> GetStockSelectListItemsWithOptionGroup(Company[] companies, Stock[] stocks) | |
{ | |
var optionGroups = companies.GroupBy(c => c.CompanyId, c => c.CompanyName).Select(c => new SelectListGroup { Name = c.First() }); | |
return stocks.Select(s => new SelectListItem | |
{ | |
Text = s.StockName, | |
Value = s.StockId.ToString(), | |
Group = optionGroups.Single(o => o.Name.Trim() == s.CompanyName.Trim()) | |
}).ToList(); |
This file contains 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
public class Quote | |
{ | |
public string Word { get; set; } | |
} | |
[Fact] | |
void LinqSingleMethod_WhenLazilyEvaluated_ReturnsDifferentInstance() | |
{ | |
var quoteWords = new[] | |
{ |
This file contains 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
[Fact] | |
public async Task DetailPassTheCorrectIdIntoPortfolioByIdQuery() | |
{ | |
//This is a mock | |
var _mediator = new Mock<IMediator>() ; | |
var _mapper = new Mock<IMapper>(); | |
//Arrange | |
var sut = new PortfolioController(_mapper.Object, _mediator.Object); |
This file contains 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
//Moq | |
var lollipop = new Mock<ICandy>(); | |
var shop = new Mock<ICandyShop>(); | |
shop.Setup(s => s.GetTopSellingCandy()).Returns(lollipop); | |
shop.Verify(s => s.BuyCandy(lollipop), Times.AtMostOnce()); | |
//NSubstitude | |
var lollipop = Substitute.For<ICandy>(); | |
var shop = Substitute.For<ICandyShop>(); | |
shop.GetTopSellingCandy().Returns(lollipop); |
This file contains 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
public class Startup | |
{ | |
public Startup(IConfiguration configuration, IHostingEnvironment env) | |
{ | |
var builder = new ConfigurationBuilder() | |
.SetBasePath(env.ContentRootPath) | |
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); | |
Configuration = builder.Build(); | |
} |
This file contains 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
[Produces("application/json")] | |
[Route("api/Product")] | |
public class ProductApiController : Controller | |
{ | |
public OkObjectResult Get() | |
{ | |
var products = new { Products = new[] { new { Id = 1, Name = "Normal Bear" }, new { Id = 2, Name = "Panda Bearer" }, new { Id = 3, Name = "JWT Bearer" } } }; | |
return Ok(products); | |
} |
This file contains 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
[Produces("application/json")] | |
[Route("api/Product")] | |
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme, Policy = "Trusted")] | |
public class ProductApiController : Controller | |
{ | |
public OkObjectResult Get() | |
{ | |
var products = new { Products = new[] { new { Id = 1, Name = "Normal Bear" }, new { Id = 2, Name = "Panda Bearer" }, new { Id = 3, Name = "JWT Bearer" } } }; | |
return Ok(products); |
This file contains 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
[AllowAnonymous] | |
[HttpPost] | |
public async Task<IActionResult> Generate([FromBody] LoginViewModel model) | |
{ | |
if (!ModelState.IsValid) return BadRequest("Could not create token"); | |
var user = await _userManager.FindByEmailAsync(model.Email); | |
if (user == null) return BadRequest("Could not create token"); |
OlderNewer