MongoDB tips

Change user password

db.updateUser(){ , { pwd: ""}}

Choose the ID field

We do not want to pollute our entities/classes with MongoDB attributes.
WE want to store the “Email” property as ID in mongoDB (the “_id” field of the document).

SetIdMember … does not work.
MapIdMember is the right one.

protected override void MapEntity()
if (!BsonClassMap.IsClassMapRegistered(typeof(Account)))
BsonClassMap.RegisterClassMap(map =>
map.MapIdMember(c => c.Email);


My C# cheat sheet

Missing XML comment
Add to the Project properties > Build > Suppress warnings the value “1591“. Use “;” to separate values.

Visual Studio Post-Build command, this is the way:
if $(ConfigurationName) == Debug (
echo create doc
) else (
echo bye

Connection fail to SQL Server after a database restore


Restore SQL Server database X.
Try to conenct using the usual connection string. Conenction fail.

Delete the user in “Security” of SQL Server.
Delete the user from the “Users” of the database.
Create a new user in Server/Securit6y/Logins:
– User name: seelct a user that exists in the machine, ex.: \user
– leave everything unchaged
Create a user in the database in database/Security/Users:
– Login namne: seelct <achine\
– User name: select \
> Yes
< Do you use an IP address in the connection string?

in the database:
– User name: select / using hhe selector
– Login name:
– Default schema:
> No
Check the user defined in the Application Pool of the current web site
> No
> No

MVC API tests – manage unknown error raised by HttpServer

Scenario: integration tests against ASP.Net MVC API.
MVC version 5.2

Create a base class test to manage the repetitive API GET/POST calls like:

protected HttpResponseMessage Execute(HttpMethod method, string url, T data)
url = BASE_URL + url;

HttpRequestMessage request = new HttpRequestMessage(method, url);
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

JsonMediaTypeFormatter formatter = new JsonMediaTypeFormatter();
formatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
if (method == HttpMethod.Post && data != null)
request.Content = new ObjectContent(data, formatter);

using (var server = new HttpServer(GetConfiguration()))
using (var client = new HttpClient(server))
var response = client.SendAsync(request).Result;
return response;


500. Internal server Error.

The server is set like this:
private HttpConfiguration GetConfiguration()
HttpConfiguration configuration = new HttpConfiguration();
//var dependencyResolver = new WindsorDependencyResolver(container);
//configuration.DependencyResolver = dependencyResolver;

// remove all HostAuthenticationFilter due to the error “no OWIN Authentication manager…”
foreach (var filter in configuration.Filters.Where(f => f.Instance is HostAuthenticationFilter).ToList())

return configuration;

mmhh… try to debug:
It enter in the ApiController, get the data from the REpository and it exit from the class with a nice colelction of data… what is wrong ???

Routing is ok, it is actually passing the request to the right controller.
Injection of repositories is ok, it is fetching and returning data.
Log4Net is ok, I’m not calling the “log4net.Config.XmlConfigurator.Configure();” without a proper configuration in app.config.

Adding “configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;”
is absolutely useless for this problem.

What to do now?

I’ll check one of 2 or 3 previous project where I’ve already done this a where I spent 1,2 or 7 days to figure out this ALL THE TIMES fucking problem !

GIT Merge vs Rebase


When you merge a branch into another you apply both the changes done in the two branches to the final one.
In the picture example there is a merge of the changes in C4 and C5 resulting in C6.
It is a 3 way merging because it involves the common origin commit C3.


When you rebase a branch on another you apply the specific commit of the branch on the one you are.
In the picture example the changes in C5 are reapplied to the commit C4 resulting in C5.


The result of the two operations is the same.
The goal to use Rebasing is to have a cleaner history of the changes, as they appear executed sequentially instead of in parallel.

My 2 cent

Imagine this situation.
You have done 10 changes on a branch called “Create modal dialog for new Order”.
You rebase the commits of this branch on the master branch.
For the commit “Add form validation on save button click” how someone can understand which “save” button you are talking about ?
If the reabase put all the commits under the main branch how can I see the work done for a specific feature/bug ? Detaching the commits from a specific branch seems a loose of information to me.


ReSharper, what I don’t like of it

Versione 9.0 Update 1

No… these NOT:

  • use “var”
  • remove “using System;” (and System.Linq, System.Net, System.Net.Http…)
  • Intellisense: set on “Visual Studio”. With “ReSharper” selection I’ve not found immediately how to navigate overrides of method and it hide beautiful intellisense for AngularJS (and HTML%, CSS and HTML/Javascript in general from the fantastic “Web Essentials” free plugin)
  • JavaScript quote style. I have some with ‘ (single qutote) and some with ” (double quote), whart’s wrong?!
  • JavaScript: Function parameters not all in lowerCamelCase. Sorry, AngularJS style
  • Namespace does not correspond to file location. This is not Java, I want “MyProject.Test.IntegrationTest.MvcApplication.Api namespace for folder “Integration Test/MVC Appication/API”
  • Constant field (private) in “lowerCalmelCase”. No, I want the classic UPPER_CASE for constants
  • Possible multiple enumeration of IEnumerable. I’ve to live with that noise forever?
  • Constant field (not private) in “lowerCalmelCase”. No, I want the classic UPPER_CASE for constants
  • Field (not private) in “UpperCalmelCase”. No, I want the classic lowerCamelCase for this
  • Instance fields (private). Suggested name is “_xxx”. With underscore prefix? Why???
  • Use object initializer on EVERY new MyClass() in the code… ???
  • Field can be made readonly. Yes, yes, yes… but in test classes this is useless and code is more concise and readable without “readonly” everywhere.
  • JavaScript: Cannot resolve tag “…”. Of course! It is and AngularJS directive.
  • JavaScript: Replace with “strict” operator. No not everywhere!

WOW… this is very good

  • Class XXX inherited (click ti navigate)