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
void Should_Insert_Entity() | |
{ | |
// Arrange | |
var entity = new Account | |
{ | |
Id = "1", | |
Name = "first_Account", | |
IsActive = true, | |
CreatedOn = DateTime.UtcNow | |
}; |
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 ProductController | |
{ | |
[HttPost] | |
public ActionResult Create([FromBody] Product model) | |
{ | |
using(var dbContext = new ProductContext()) | |
{ | |
dbContext.Products.Add(model); | |
dbContext.SaveChanges(); | |
} |
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 IProductRepository { | |
bool Create(Product product); | |
bool Delete(int productId); | |
IEnumerable<Product> GetAll(); | |
void DeleteAll(); | |
} |
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 ProductRepository : IProductRepository | |
{ | |
public ProductRepository(DbContext dbContenxt) { | |
_table = dbContext.Set<Product>(); | |
_dbContext = dbContext; | |
} | |
public bool Create(Product product) { | |
_table.Add(product); | |
return Save(); |
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 ProductController | |
{ | |
public ProductController(IProductRepository productRepository) | |
{ | |
_productRepository = productRepository; | |
} | |
[HttPost] | |
public ActionResult Create([FromBody] Product model) | |
{ |
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
[TestFixture] | |
public class ProductRepositoryFixture | |
{ | |
public ProductRepositoryFixture() | |
{ | |
var builder = new SqlConnectionStringBuilder("Database connection string here!"); | |
var dbContext = new DbContext(builder.ToString()); | |
_prdocutRepository = new ProductRepository(dbContext); | |
} | |
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
$totalRam = (Get-CimInstance Win32_PhysicalMemory | Measure-Object -Property capacity -Sum).Sum | |
while($true) { | |
$date = Get-Date -Format "yyyy-MM-dd HH:mm:ss" | |
$cpuTime = (Get-Counter '\Processor(_Total)\% Processor Time').CounterSamples.CookedValue | |
$availMem = (Get-Counter '\Memory\Available MBytes').CounterSamples.CookedValue | |
$date + ' > CPU: ' + $cpuTime.ToString("#,0.000") + '%, Avail. Mem.: ' + $availMem.ToString("N0") + 'MB (' + (104857600 * $availMem / $totalRam).ToString("#,0.0") + '%)' | |
Start-Sleep -s 2 | |
} |