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
[TestMethod] | |
public async Task ShouldSetGetCache() | |
{ | |
var options = new DbContextOptionsBuilder<ImmutableCacheDbContext>() | |
.UseInMemoryDatabase(databaseName: "LotNamesCacheTests") | |
.Options; | |
using (var dbContext = new ImmutableCacheDbContext(options)) | |
{ | |
var lot1 = Mock.Of<ParkingLot>(x => x.LotCode == "02" && x.LotName == "Lot 02"); |
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
// you can play with the following code snippet in browser console. | |
let person = {name: 'John Doe'} | |
console.log(person.name) | |
// John Doe | |
person.__proto__.toString = () => {alert('evil')} | |
console.log(person.name) | |
// an alert box with "evil" pops up |
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
const isObject = obj => obj && obj.constructor && obj.constructor === Object; | |
function merge(dest, src) { | |
for (var attr in src) { | |
if (isObject(dest[attr]) && isObject(src[attr])) { | |
merge(dest[attr], src[attr]); | |
} else { | |
dest[attr] = src[attr]; | |
} | |
} | |
return dest |
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
var userInput = JSON.parse('{"__proto__": {"admin": true}}') | |
var a = {...userInput} | |
console.log(a.admin) | |
// true | |
var b = Object.assign({}, userInput) | |
console.log(b.admin) | |
// true |
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
return await _dbContext.Authors | |
.Where(Author.GoldAndUp) // expression works with IQueryable | |
.Select(x => new AuthorViewModel(x)) | |
.ToListAsync(); |
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
var authors = await _dbContext.Authors.ToListAsync(); // data is in memory | |
var goldAndUpAuthors = authors // IEnumerable | |
.Where(Author.GoldAndUp.Compile()) | |
.Select(x => new AuthorViewModel(x)) | |
.ToList(); |
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
public class CalculationService : ICalculationService | |
{ | |
private readonly ILogger<CalculationService> _logger; | |
public CalculationService(ILogger<CalculationService> logger) | |
{ | |
_logger = logger; | |
} | |
public int AddTwoPositiveNumbers(int a, int b) |
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
public class CalculationService : ICalculationService | |
{ | |
private readonly ILogger<CalculationService> _logger; | |
public CalculationService(ILogger<CalculationService> logger) | |
{ | |
_logger = logger; | |
} | |
public int AddTwoPositiveNumbers(int a, int b) |
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
public static class MockLoggerExtensions | |
{ | |
public static void VerifyLog<T>(this Mock<ILogger<T>> loggerMock, LogLevel level, string message, string failMessage = null) | |
{ | |
loggerMock.VerifyLog(level, message, Times.Once(), failMessage); | |
} | |
public static void VerifyLog<T>(this Mock<ILogger<T>> loggerMock, LogLevel level, string message, Times times, string failMessage = null) | |
{ | |
loggerMock.Verify(l => l.Log(level, It.IsAny<EventId>(), | |
It.Is<It.IsAnyType>((o, _) => o.ToString() == message), It.IsAny<Exception>(), |