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
function createUser(uname: string, pw: string): User { | |
if (!(uname && pw)) | |
throw new Error("Validation failed!"); | |
return { username: uname, password: pw }; | |
} | |
try { | |
createUser("John Doe", "hello123"); | |
} catch (error) { | |
throw error; |
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
//#region The 'let' keyword | |
//let <identifier> = <value> | |
let a = 0 | |
let b = 0.0 //64-bit a.k.a double | |
let c = 0.0m //decimal | |
let d = "Hello World!" | |
let e = "Hello" + "World" | |
let f = """{ "word1": "Hello", |
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
open System.IO | |
let writeTransactionToFile transaction = File.AppendAllText("statement.txt", "some string") | |
let writeTransactionToConsole transaction = printfn "%s" "Something" | |
//Forstsätt där vi avslutade uppgift 3 | |
//1. Bygg ut "transaction" funktionerna så att dom har loggningsfunktionalitet | |
// - Försök experimentera med Higher-order functions, currying och partial application. |
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
// -------------------------------------------------------------------------------------- | |
// FAKE build script | |
// -------------------------------------------------------------------------------------- | |
#r "./packages/build/FAKE/tools/FakeLib.dll" | |
open Fake | |
open System | |
// -------------------------------------------------------------------------------------- |
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
//Read | |
//BsonDocument | |
var collection = db.GetCollection<BsonDocument>("people"); | |
var builder = Builders<BsonDocument>.Filter; | |
//Note that the '&' '!' '|' operators are overloaded when used in the FilterBuilder | |
var filter = builder.Lt("Age", 33) & !builder.Eq("Name", "Ericsson"); | |
var list = await collection.Find(filter).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
public static void Main(string[] args) | |
{ | |
//Needs to be configured before we start handling MongoDB | |
var conventionPack = new ConventionPack(); | |
conventionPack.Add(new CamelCaseElementNameConvention()); | |
ConventionRegistry.Register("camelCase", conventionPack, typesAppliedTo => true); | |
//typesAppliedTo => true will apply the convention to all types. |
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
[HttpGet("{id}", Name = "GetBlog")] | |
public async Task<IActionResult> Get(string id) | |
{ | |
if (!ObjectId.TryParse(id, out var objectId)) | |
return BadRequest($"The id provided ({id}) is not a valid id."); | |
try | |
{ | |
var blog = await _blogDataService.FindBlogByIdAsync(objectId); |
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 Microsoft.AspNetCore.Authorization; | |
namespace OpenBlog.Api.Authorization.Requirements | |
{ | |
public class ResourceOwnerRequirement : IAuthorizationRequirement | |
{ | |
} | |
} |
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 AutoFixture; | |
using AutoFixture.AutoMoq; | |
using AutoFixture.Xunit2; | |
namespace AutoFixtureSandbox.Tests | |
{ | |
public class AutoMoqDataAttribute : AutoDataAttribute | |
{ | |
public AutoMoqDataAttribute() : base(() => | |
{ |
NewerOlder