Search

Categories

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Send mail to the author(s) E-mail

# Thursday, September 18, 2014

https://uptimerobot.com

A free service that keeps an eye on up to 50 websites.  Can access every 5 minutes.

Useful for Azure websites which are slow to startup after 20minutes? of inaction.

| | # 

image

Got a small SSD and 10GB of AppData - 8GB in Local.  So moving to E.

| | # 
# Wednesday, September 17, 2014

image

Click bottom right thing,  Options, All Styles.

image

Should see all Headings now.

| | # 
# Saturday, September 13, 2014
( Project )

Strategy is to take a slice through an application ie end to end, and refactor

Paired with DaveH for an hour of coding – great to talk through and refactor code with someone else.

Renaming Stories to Jokes

What started out as a good idea, turned out to be confusing.  As my site principally has ‘jokes’ with a few videos and pictures, it is easier to think of each entity as a ‘Joke’.  So renamed it all through the stack, even to the DB Table.

Pure DI in MVC

image
Simple slice through an app – showing how to do simple DI in MVC, and display 1 table (Jokes).

Have split the Core and Web apart (not really necessary at the moment) – but will need a console app to do imports.

Testing

Unit testing here for fun, to see how good the composed app of disparate parts is.  Whereas I really do like Integration tests. 

Trying to figure out how to easily mock out the Session (FakeSession) so can unit test the services

http://thedatafarm.com/data-access/how-ef6-enables-mocking-dbsets-more-easily/

http://msdn.microsoft.com/en-us/data/dn314431.aspx – shows how to do a test doubles - an in memory collection based on DbSet<T>

at System.Linq.Queryable.OrderBy[TSource,TKey](IQueryable`1 source, Expression`1 keySelector)

image

Something wrong with Queryable in my test double implementation?

IQueryProvider IQueryable.Provider {
    get {
        return null; //return new TestDbAsyncQueryProvider<TEntity>(_query.Provider); }
    }
}

Had commented this out to get rid of Async code – oops.  All works when I implement this.

AddJokes

Ctrl Shift R – Refactor menu in R#.  Pull members up to add to existing interface.

[Fact]
public void AddJoke_GivenTitleAndRating_ShouldSaveToDbAndBeAvailableInTheSession()
{
    var session = new FakeSession();
    var viewer = new JokeViewer(session);

    var result = viewer.AddJoke("sausage", 2);

    Assert.Equal(1, session.Jokes.Count());
    Assert.Equal("sausage", session.Jokes.Single().Title);
    Assert.Equal(2, session.Jokes.Single().Rating);
    Assert.Equal(1, session.SaveChangesCount);
}

Interesting to be able to mock out EF and unit test it.

Class Diagram from Tests Project

image
As the tests project references all the others, then creating a ClassDiagram from it is great, as all the classes are available.

NCrunch

Enabling NCrunch for these Unit tests as they are nice and fast!

Integration Testing

End to end testing and diagram what is going on too.  Bringing in the integration tests.  Referenced EF from tests project, and putting connection string into app.config so R# test runner can connect to the db.

“The model backing the 'Session' context has changed since the database was created. Consider using Code First Migrations to update the database “

    public class Session : DbContext, ISession {
        public Session() : base(nameOrConnectionString: "Funny") {
            // Nice for development
            Database.SetInitializer(new DropCreateDatabaseIfModelChanges<Session>());
        }
        public DbSet<Joke> Jokes { get; set; }
    }

A CodeFirst handy method, so if something changes in the way the db is defined, then the table is auto generated.

image
VS Test runner showing xUnit traits well.  But R# not showing the trait attributes.

Multiple Tables

asfd

| | # 
# Thursday, September 11, 2014

SOLID vs YAGNI and Design Patterns
Simplicity vs testability and maintainability

Poor Mans DI / Pure DI – Overall app design with
MVC
Decorator – Logging
Repository – Data Access
Pipline?
        polymorphism

common patterns and common usages

| | # 
# Monday, September 08, 2014

Goal is to rewrite www.davesjokes.co.uk in a SOLID way:

Source is:  https://github.com/djhmateer/solidjokes

  • Single Responsibility
  • Open Closed Principle
  • Liskov substitution
  • Interface segregation
  • Dependency Inversion

Pure DI (Poor Mans), aim for open closed and SRP so testing is easier and  Decorator for logging

public class HomeController : Controller {
    private readonly ILogger logger;

    public HomeController() {
        logger = new Logger();
    }

    // So this is useful for testing now
    public HomeController(ILogger logger) {
        this.logger = logger;
    }

    public ActionResult Index() {
        logger.Log("In Index of Home Controller");
        return View();
    }

    public ActionResult About() {
        ViewBag.Message = "Your application description page.";

        return View();
    }

    public ActionResult Contact() {
        ViewBag.Message = "Your contact page.";

        return View();
    }
}

public interface ILogger { void Log(string text);}
public class Logger : ILogger {
    public void Log(string text) {
        Console.WriteLine(text);
    }
}

Simplest possible DI in MVC – in fact we’re only using DI when it’s called from a test method through the overloaded ctor.
public class HomeController : Controller {
    private readonly ILogger logger;

    public HomeController(ILogger logger) {
        this.logger = logger;
    }

    public ActionResult Index() {
        logger.Log("In Index of Home Controller");
        return View();
    }

    public ActionResult About() {
        ViewBag.Message = "Your application description page.";
        return View();
    }

    public ActionResult Contact() {
        ViewBag.Message = "Your contact page.";
        return View();
    }
}

public interface ILogger { void Log(string text);}
public class Logger : ILogger {
    public void Log(string text) {
        Console.WriteLine(text);
        Debug.WriteLine(text);
    }
}
public class MvcApplication : System.Web.HttpApplication {
    protected void Application_Start() {
        AreaRegistration.RegisterAllAreas();
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);

        // Patch in our own Factory/Composition Root into MVC pipeline
        var controllerFactory = new SolidJokesControllerFactory();
        ControllerBuilder.Current.SetControllerFactory(controllerFactory);
    }
}

public class SolidJokesControllerFactory : DefaultControllerFactory {
    protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType) {
        var logger = new Logger();
        if (controllerType == typeof(HomeController)) {
            return new HomeController(logger);
        }

        return base.GetControllerInstance(requestContext, controllerType);
    }
}

image
Debug.WriteLine logging, and our own Pure DI setup in the simplest way.

SRP – Decorating a Controller

HomeController has logging inside of it.  Lets decorate it, so making sure the HomeController does only 1 thing.

public class SolidJokesControllerFactory : DefaultControllerFactory {
    protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType) {
        if (controllerType == typeof(HomeController)) {
            // Decorating HomeController with HomeControllerLogger
            return new HomeControllerLogger(new HomeController());
        }
        // AccountController will still go the normal tightly coupled way
        return base.GetControllerInstance(requestContext, controllerType);
    }
}
public interface IHomeController
{
    ActionResult Index();
    ActionResult About();
    ActionResult Contact();
}
    public class HomeControllerLogger : Controller, IHomeController {
        private readonly IHomeController homeController;

        public HomeControllerLogger(IHomeController homeController) {
            this.homeController = homeController;
        }

        public ActionResult Index() {
            Debug.WriteLine("In Index of HomeControllerLogger");
            var result = homeController.Index();
            Debug.WriteLine("End Index of HomeControllerLogger");
            return result;
        }

        public ActionResult About() {
            Debug.WriteLine("In About of HomeControllerLogger");
            var result = homeController.About();
            Debug.WriteLine("End About of HomeControllerLogger");
            return result;
        }

        public ActionResult Contact() {
            return homeController.Contact();
        }
    }

image

Added in a test project to solution taking the boilerplate tests from VS2013.  Using xunit.  Updated references and went to MVC5.2.2 in both projects.

| | # 
# Thursday, September 04, 2014
# Tuesday, September 02, 2014
  • Emphasise, not summaraise
  • Concepts and syntax belong in demos
  • Bullet points put people to sleep!

People want to see live coding in action

Rob records all live coding for each video – 20 to 30 videos!

Presenter notes – cues

Who I am

What this is about

why should they care

Colours and Fonts

kuler.adobe.com

colourlover.com

fontsquirrel.com – Title: ChunkFive  Body: Helvetica Neuve

20mins through – Rob Creates a slide deck

| | # 
# Thursday, August 28, 2014
( )

Telling a good story is an art (Narrative Structure)

Narrative Structure

Prologue – always give away the ending!.. how final demo? 5mins

Beginning – introduction to main characters.. 15mins

Middle .. conflict.. 15mins

End – grand finale!

image

The Plot…..

 

Motives, what impressed me…

eg

Along Came Sails

Wow! This is just what I need

Oh well, nothing is perfect

Open Source to the rescue

Demos

Simple, Easy to Understand, Real World example

relevant to the audience.

Leisurely pace

- GitHub or Twitter for external API (video it!)
- User admin

Coding on Stage

prepare the code beforehand (in a textfile).. eg 1.txt. 2.txt.. then a completed folder (solution)

code snippets in a utility bar

Slide Techniques

zach holman – huge fonts

slide designs are great

http://zachholman.com/posts/slide-design-for-developers/

or speaking.io

image

A good image.. subtle.  Contrast down.

Slide Deck

Emphasize, not summerise

| | #