Friday, December 16, 2016

ForgeSCMC using GIT on Forge.mil

There are many reasons I am excited to see git support on Forge.mil. Below are a few notes on successfully using early versions of the ForgeSCMC tool.

The following scenario assumes you use a different git repository than forge.mil as the primary development repository and that you need to push released code to forge.mil as part of a contractual agreement.

My daily git client is Github for Desktop, and sometimes SourceTree.  I use ForgeSCMC only to push code to forge.mil.

Setting UP
There are several documents, the one you need to read is the "Git-Gerrit Users Guide.docx".  Pay special attention to the sections covering Git Developer and Git Reviewer role setup and the section "Assigning Source Code Permissions to Roles"

Quick Tips
Some of these tips are not fully tested, so your mileage may vary.

If you are a GitHub, GitLab, BitBucket, or VSTS user, your standard workflow will not work for pushing code to Forge.mil. You will need to follow the Gerrit Workflow that is commit based and not branch based.

Create a single commit from a dev branch using
git merge --squash <featurebranch> 

Commits are a bit different than GitHub or VSTS.

git commit -m 'my message' //will not work using ForgeSCMC

git commit -a -m "my message" //works: notice the double quotes and the ammend command.

Amends are required because forge uses Gerrit as the code review tool.  Gerrit is commit based, wile VSTS and GitHub are branch based. I've read that the Google Gerrit team wants to remedy this but, but when they built Gerrit, the copied the workflow of their existing tool.

Keep both remote repositories in sync by add the forge.mil repo as a remote using your primary git client. ForgeSCMC does not support the remote add command. This is a one time step

git add remote forge https://yourProjectUrlHere










Monday, April 4, 2016

Open Source With Scott Hanselman

I love watching Scott Hanselman present, (who doesn't.)  But I had a pretty busy schedule at Microsoft Build 2016 and chose to skip Scott's talk on Open Source.  I've been doing open source for a while and thought I'd get more value out of standing inline to get HoloLense tickets. (Might be my only chance to use a HoloLense for at least a year, probably two.)

When I saw the line  CRAZY MOB for HoloLense.  I went to hear Scott speak and IT WAS THE BEST TALK!  He even joked that he was overflow for HoloLense.

The talk was about open source, but leave it Scott to hit it from a completely different angle.  I hope they publish his talk, it was one that every developer should see!

Have some fun!  If you are doing forms over data all day and hate it. Try something else in your spare time like play with Arduino or Raspberry Pi (I was like, hey that's me.  I'm always playing with physical computing! Although I still enjoy my forms over data work.  It is a nice break from my managerial responsibilities.)

Helping Others:  Scott pointed out some sites for people just getting started and are willing to help new people and be kind about it. http://www.firsttimersonly.com/

Self Worth: Don't tie your self worth or value to the number of GitHub Stars your project has, or the number of projects you have contributed to.  Be proud of what you were able to accomplish. This area has always been easy for me.  I'm rather proud of my 600+ points on stack overflow.  I'm glad the minimal amount of work I've done has been able to impact so many people.  I have a few questions that have been viewed over ten-thousand times!  I do wish that I had started participating on Stack Overflow much earlier, I missed out on some fun. (Wait is that being hard on myself? Well a little motivating pain can be a good thing. )



 

Friday, March 18, 2016

Upgrading to Angular Component Router

I have a use case where I can benefit from upgrading to the 'new' component router in AngularJs 1.5. Below are my very quickly jotted down notes.

Wow! My app is so much faster after the upgrade!

I needed to have nested routes.  Basically a list of (different) things on the left nav.  When clicked, the correct controller and view need to show in the center of the page.
For HTML I'm using Bootstrap so the initial html is pretty easy, just a row with two columns (col-md-3, col-md-9)

My primary resource is the AngularJs docs .

I decided to NOT upgrade to html 5 routing mode.

I'm ripping out my old routing, although I'm not quite confident I need to do this.


  • I started by making my top nav an angular component. This is the top level of the component tree.
    • I pulled the top nav (html) out of the index.html and making a topNav.html template.
    • Then I basically copied the component example in the AngularJs docs. Kept this in my index.js file or the ng-app's first controller file.
    • changed the ng-href's into ng-links in the topNav.html
    • wired up all the immediate routes mentioned in the topNav
      • which leads to making components in all the other modules
      • I'm working them one at a time.
      • Read the docs carefully, if your routes have sub routes you have to include /... in your parent route definition.
  • Converting an existing controller over to a component.
    • follow the example in the docs
    • I'm using the vm.foo syntax in the controller, I kept that but also added an extra line, might be unnecessary though
      • $ctrl = this
    • changed all my controllerAs syntax for ctrl to $ctrl in my HTML (had to do this.)
    • Another big gotcha was route parameters
      • required and optional, you will need to visit the AngularJs 2.0 docs for this. 
      • The biggest unexpected part is the syntax changes based on the route definition
        • if in the ng-link you have extra parameters (that are not in the route definition) they will show up as optional parameters in either ?foo=bar or ;foo=bar.
        • Usually the required parameters show up in the route like #/user/eric
    • $location.search('id',vm..selectedThing.id) is now
      •  this.$router.navigate(['MyThingRoute', { id: vm.selectedThing.id }]);
  • Navigating to a nested component from a home or other page.
    • <a ng-link="['UsersList','UserDetail',{userId:$ctrl.id}]">{{$ctrl.name}}</a>
      • This invokes the UsersList component, then the UserDetail component, and then the user id is added to the route auto-magically.


Thursday, May 7, 2015

Unit Testing Invalid Model State in a WebApi 2 Controller

I choose to do this operation in two different tests.
1. Test the controller behavior when the model state is invalid.  Do this by forcing the model state to invalid by adding an entry before the method is called.
2. Test the model state attributes independently from the controller.

For the controller Test

[TestMethod]
public void WhenModelStateIsInvalidDoNotSave()
{
  var mockRepo = new Mock<IProductRepo>();
  mockRepo.Setup(x=>x.Save(It.IsAny<Product>());

  var ctrl = new ProductController(mockRepo.Object);
  ctrl.ModelState.AddModelError("SomeRandomProperty","SomeRandomProperty was not valid");

  var actual = ctrl.Post(new Product());

  mockRepo.Verify(x=>x.Save(It.IsAny<int>()),Times.Never);
  Assert.IsInstanceOfType(actual, typeof(InvalidModelStateResult));
}


public IHttpActionResult Post([FromBody] Product model)
{
  if(!ModelState.IsValid)
    {
       return BadRequest(ModelState);
     }
   
   ProductRepo.Save(model);
    return Ok();
}

Wednesday, March 25, 2015

AngularJs Style Guide

Simple but radical concept, have the tests right next to the code.  In server side code, I'm so used to separating tests into a separate project. On some projects I work on the tests need to be stripped out for the production build, even thought unit tests should be harmless, but not my call.  This can be done with the build scripts, if needed.

There are many other gems in this document, check it out.
https://github.com/johnpapa/angular-styleguide#organizing-tests

Tuesday, March 10, 2015

Creating a self signed cert using makecert

http://www.jayway.com/2014/09/03/creating-self-signed-certificates-with-makecert-exe-for-development/

"C:\Program Files (x86)\Windows Kits\8.0\bin\x86\makecert.exe" ^
-n "CN=CARoot" ^
-r ^
-pe ^
-a sha512 ^
-len 4096 ^
-cy authority ^
-sv CARoot.pvk ^
CARoot.cer

"C:\Program Files (x86)\Windows Kits\8.0\bin\x86\pvk2pfx.exe" ^
-pvk CARoot.pvk ^
-spc CARoot.cer ^
-pfx CARoot.pfx ^
-po Test123

Wednesday, March 4, 2015

WebMatrix.data

My favorite quick data access tool is WebMatrix.Data.  It went through a name change, I'm posting it here so I don't forget it. 

http://www.nuget.org/packages/Microsoft.AspNet.WebPages.Data/

Thursday, September 25, 2014

Forms Authentication Sliding Expiration and the SPA

Working on a SPA with Forms Sliding expiration.  The trick is how to let the SPA know the user has timed out.  If you make a call to the server, with sliding expiration enabled... the account will never expire.

I don't have a working solution yet, but thought I would post the observation.

Tuesday, September 23, 2014

TF-Git

Testing out TF-Git.  The tools for peer review are more robust in the git ecosystem than in TFS.  The workflow seems reasonable so far.  
 
https://gittf.codeplex.com/


Gitlab - Permissions and Groups

When setting up GitLab, before you start using it, be sure to set up a project group.  If this step is omitted, all projects are created under a user account and only that user can check in code. 

I have seen this issue three times now, so I thought I should post this.  This is unique to GitLab and there is not a visible analog in Stash or GitHub.

Tuesday, September 16, 2014

Do not use RequireJs and AngularJs

Do not use RequireJs with AngularJs.  It is premature optimization.  I have read many posts where they show how to use requireJs.  I have not seen one post that has empirical data PROOVING that using RequireJs improves the overall user experience in any significant way.

I suggest mastering alternative strategies for ng-repeat if you want to optimize something.

I spent a year and a half writing 25,000 lines of AngularJs code with no problems! We were bad developers and did not even minify and consolidating our JavaScript. The JavaScript was in ~30 different files. (We wanted to min and consolidate but the usual tools were not allowed in our secure and constrained environment.)

Most of the noise about using RequireJs is theoretical. I have yet to read a post where a team could not satisfy performance requirements established by the business using AngularJs and had to refactor to using RequireJs for lazy loading.

If the wire is your worry...

  • consolidate your JavaScript into one file,
  • minimizing that file,
  • compress files across the wire
In most AngularJs apps the images are probably larger than the JavaScript.


Even Brian Ford recommends not using RequireJs with AngularJs. http://briantford.com/blog/huuuuuge-angular-apps

I would like to post more on the mechanics of AngularJs and why I feel this way, but time is short today.

Thursday, August 28, 2014

Integration testing services with Jasmine 2.0


Testing real services using jQuery and Jasmine took some research. I saw in the docs that I needed to work with done(), but where?  The code below works.

Saturday, April 26, 2014

Optimizing Pagination with MemoryCache

In web development pagination is fairly straight forward when using out of the box components. When building custom components on expensive queries, paging is not quick to implement.

The query I needed to implement paging against was an expensive query.  After fighting and fighting, I thought why not slam the whole thing in MemCached and page against the query.  Felt kinda weird about it.  After all this would have been a major fail 10 years ago.  Then listened to Rob Conery on DotNetRocks.  In Robs new project Biggy, he stuffs the whole database in memory using ICollectionOf<T>.  Feeling validated, started down the memory path.

I was not quite ready to use Biggy, but MemCached is appropriate.  MemCached was not setup.  Then found the MemoryCache class in .NET.  There is more than one version.  One for web and one for console apps.  Nice! I mainly wanted to use MemoryCache for the expiration policies.

The performance is significantly faster than the expensive sql queries.  Creating pagination across the collection is very easy using linq.

It has been so easy to code against, I've created a few filters; light search, return only certain fields, or exclude certain fields.

Disclaimer: There is a very good reason why I'm not using an ORM or a document database that does not have this baked in.


Friday, March 14, 2014

Verify Times Once

My first WebApi controller test is usually Verify Times Once as show below.

Repo.Verify(x=>x.GetUser(It.IsAny<string>()),Times.Once);


A new member of the team questioned the value of the test. I agreed it was probably more ceremony than a realistic possible regression.
Later in the day I saw the following property in a class.

 public static IFooRepo Repo { get { return _repo ?? (_repo = new FooRepo()); } } 

The code above is tightly coupled.  I prefer loose coupling.  The property is doing the work of the constructor (assuming we are using constructor injection.)  Changing the property from static to a regular class property allows the developer to override the hard coded FooRepo with a mock repo object derived from the IFooRepo interface providing support for testing other methods.  I think we still have a problem with this pattern.  Given a class with more that one property, how will the developer know which properties need setting and which to leave alone? The developer never needs to guess what properties need to be set when the class uses constructor injection.

It might feel like ceremony to perform an obvious test like Verify Times Once, but it ensures loosely coupled code that supports future TDD style tests.

Saturday, February 15, 2014

Called out on the Switch Statement

I was going over TDD with a developer and made a statement that I avoid using switch statements. (I may have used stronger language like "never use", can't remember.)  Then a few days later, I was pair programming with the same developer and I used a switch statement.  The developer, frustrated and confused, called me out on it.  
We were working on parsing XML sax style using xmlreader and writer.  I was also copy and pasting code from the sample as a first pass to quickly get my tests to pass.  If I needed to change... that is what refactoring is for.

While I was chopping wood for the fireplace, I was reflecting on this issue and I came up with the following.  On more than one occasion, I have had to refactor switch statements to either if else statements or, in some cases, a full blown rules engine.

I have nothing against the switch statement, other than it does not leave me much room for refactoring.  The "if" statement is reduced to a boolean in both the switch and if-else.  But in the switch statement one operator immutable throughout the evaluation set.  In contrast the "if-else" allows both sides of the equation to change at each decision point.

The XML example, using switch was fine.  The problem domain is fixed and backed by well established enumerations against a very mature standard.  When I am working out something new on my own, where both sides could change, I stick with the if statement or something else that is more flexible.





Thursday, January 30, 2014

TDD and Static Methods

Static methods present a problem in TDD. Interfaces do not support static methods. This can put a damper on fluent interfaces, unless the fluent interface is first developed in a TDD-ish manner and under test, then a fluent interface is put on top of the functionality.  This is usually how it is done anyway.

Especially in TDD avoid static methods unless you have a "good" reason to use them.  Trying to reduce two lines of code down to one for invoking a class, is not a good reason (in object oriented programming.)

Monday, January 20, 2014

NorfolkJs

The very first NorfolkJs meetup tonight. Great group, even had a pair of Google glasses starring at me.

Kevin had good suggestion, next time show filters on repeat.

Also note to self, if it has been a month since doing ng-class. .. brush up before presentation lol.

Presentation was on angularjs.

Went over data binding, controllers, ng-filter, ng-class, karma test runner, jasmine, testing, and a plug for egghead.io for training.

Sunday, January 19, 2014

TDD simple definition

Stating that TDD is just red, green, refactor, is like stating all you need to know to perform an appendectomy is make a cut and remove the appendix.

Monday, January 6, 2014

MOQ and out parameters

MOQ does not support out or ref parameters.  This bring up the debate about how testing tools can limit the developers creativity.  In the end testing is important.  There are other ways to accomplish the same goal.  The out parameter is nice but, testing is nicer.

public bool hasPermissions(string context, out List<string> allPermissions);

restructured to 
public bool hasPermissions(string context, List<string> allPermissions);

Not much of a change, but I do blow out all the data passed in.

Friday, October 11, 2013

Amazon Tech bookstore

Just saw that Amazon.com has a new tech book store.  Dino Esposito was right on the front page.  Cool!