Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am antoniovalentini on github.
  • I am avalentini (https://keybase.io/avalentini) on keybase.
  • I have a public key ASA6DHro5ocNsPDaHGH_SYHdzJSD87GMDO4vYJ9ztbQc_wo

To claim this, I am signing this object:

@antoniovalentini
antoniovalentini / GetPerson.cs
Created March 18, 2021 18:23
Snippet #1 for Mapping objects made easy with AutoMapper
public PersonDto GetPerson(int id)
{
var person = _repository.GetPerson(id);
var dto = new PersonDto
{
FirstName = person.FirstName,
LastName = person.LastName,
Age = person.Age,
};
return dto;
@antoniovalentini
antoniovalentini / SearchWithGoogle.cs
Created March 18, 2021 18:02
Snippet #2 for Test your web app with Selenium
[Fact]
public void SearchWithGoogle()
{
var driver = new ChromeDriver();
driver.Url = "https://www.google.com";
Thread.Sleep(1000);
var textField = driver.FindElementByName("q");
textField.SendKeys("italy");
@antoniovalentini
antoniovalentini / SimpleTests.cs
Created March 18, 2021 18:00
Snippet #1 for Test your web app with Selenium
public class SimpleTests
{
[Fact]
public void NavigatePage()
{
var driver = new ChromeDriver();
driver.Url = "https://www.google.com";
Thread.Sleep(3000);
driver.Dispose();
}
@antoniovalentini
antoniovalentini / NavigateToStatusPage.cs
Last active March 18, 2021 18:00
Snippet #3 for Test your web app with Selenium
[Fact]
public void NavigateToStatusPage_AssertStatusIsOk()
{
var driver = new ChromeDriver();
driver.Url = "https://status.discordapp.com/";
try
{
var statusField = driver.FindElementByCssSelector("span.status");
Assert.NotNull(statusField.Text);
@antoniovalentini
antoniovalentini / PointToMouse.cs
Created March 18, 2021 17:38
Snippet #1 for Rotate an object towards the mouse position
private void PointToMouse(Transform player)
{
var mouseScreenPos = Input.mousePosition;
var startingScreenPos = mainCamera.WorldToScreenPoint(player.position);
mouseScreenPos.x -= startingScreenPos.x;
mouseScreenPos.y -= startingScreenPos.y;
var angle = Mathf.Atan2(mouseScreenPos.y, mouseScreenPos.x) * Mathf.Rad2Deg;
player.rotation = Quaternion.Euler(new Vector3(0, 0, angle));
}
using System;
using System.Collections.Generic;
public class C {
public static void Main() {
var A = new Point(1, 2);
var A1 = new Point(1, 2);
var B = new Point(3, 4);
if (A == B) Console.WriteLine("A == B");
using System;
using System.Collections.Generic;
public class C {
public static void Main() {
var ma = new[] {new Mutable(1)};
ma[0].Increment();
// X has been changed!
if (ma[0].X != 2) throw new Exception("ma[0].X != 2");
@antoniovalentini
antoniovalentini / EvilNulls.cs
Last active March 28, 2020 10:59
How to use 'is object' to fight bad equality operator overrides
using System;
public class C {
public static void Main() {
Evil evilNull = null;
Evil evilNotNull = new Evil();
if (evilNull != null) Console.WriteLine("evilNull != null - WRONG");
if (evilNotNull == null) Console.WriteLine("evilNotNull == null - WRONG");
if (evilNull is object) Console.WriteLine("evilNull is object");