public void AVersionedApplicationIsReturedWhenCreated()
        {
            var stateStoreSpy = new VersionApplicationStateStoreMock();

            var classUnderTest = new ApplicationVersionKeeper(stateStoreSpy);
            VersionedApplication versionedApplication = classUnderTest.AddVersionedApplication("TestApplication", "Application Description");

            Assert.That(versionedApplication, Is.Not.Null);
        }
        public void CreatingANewApplicationCallsTheStateStore()
        {
            var stateStoreSpy = new VersionApplicationStateStoreMock();

            var classUnderTest = new ApplicationVersionKeeper(stateStoreSpy);
            classUnderTest.AddVersionedApplication("TestApplication", "Application Description");

            stateStoreSpy.AssertThisApplicationWasCreated("TestApplication", "Application Description");
        }
        public void WhenApplicationWithSameNameExistsReturnsDuplicateResult()
        {
            var state = new VersionedApplicationState("test", "description");
            var stateStoreSpy = new VersionApplicationStateStoreMock();
            stateStoreSpy.SetupApplicationStateToReturn(state);

            var classUnderTest = new ApplicationVersionKeeper(stateStoreSpy);

            var existingApplication = classUnderTest.AddVersionedApplication("test", "other description");
            Assert.That(existingApplication, Is.TypeOf<ExistingVersionedApplication>());
        }
        private static VersionedApplication ConfigureVersionKeeperWithApplicationState(VersionedApplicationState applicationState = null)
        {
            if (applicationState == null)
                applicationState = new VersionedApplicationState("name", "desc");

            var versionApplicationStateStoreMock = new VersionApplicationStateStoreMock();
            versionApplicationStateStoreMock.SetupApplicationStateToReturn(applicationState);
            var classUnderTest = new ApplicationVersionKeeper(versionApplicationStateStoreMock);
            VersionedApplication application = classUnderTest.AddVersionedApplication("name", "desc");
            return application;
        }
        public void CanRetrieveAnApplicationWhenItIsTheStateStore()
        {
            const string applicationDescription = "description";
            const string applicationName = "test";

            var stateStore = new VersionApplicationStateStoreMock();
            stateStore.SetupApplicationStateToReturn(new VersionedApplicationState(applicationName, applicationDescription));

            var classUnderTest = new ApplicationVersionKeeper(stateStore);
            VersionedApplication application = classUnderTest.GetVersionedApplication(applicationName);

            Assert.That(application, Is.Not.Null);
            Assert.That(application.Name, Is.EqualTo(applicationName));
            Assert.That(application.Description, Is.EqualTo(applicationDescription));

            stateStore.AssertThisApplicationNameWasRequested(applicationName);
        }
        private static ApplicationVersionKeeper BuildUpClassWithNewApplication(string applicationName, VersionApplicationStateStoreMock stateStore = null)
        {
            if (stateStore == null)
                stateStore = new VersionApplicationStateStoreMock();

            var versionedApplicationState = new VersionedApplicationState(applicationName, "");
            stateStore.SetupApplicationStateToReturn(versionedApplicationState);
            var classUnderTest = new ApplicationVersionKeeper(stateStore);
            return classUnderTest;
        }
        public void VersionNumberIncrementedCorrectlyAccrossInstancesOfVersionKeeper()
        {
            const string applicationName = "test";

            var stateStore = new VersionApplicationStateStoreMock();

            ApplicationVersionKeeper firstInstanceOfApplicationVersionKeeper = BuildUpClassWithNewApplication(applicationName, stateStore);
            VersionedApplication application = firstInstanceOfApplicationVersionKeeper.GetVersionedApplication(applicationName);

            string firstVersionControlNumber = GenerateRandomVersionControlIdentifier();
            application.RecordBuild(firstVersionControlNumber);
            application.RecordBuild(firstVersionControlNumber);

            string secondVersionControlNumber = GenerateRandomVersionControlIdentifier();

            application.RecordBuild(secondVersionControlNumber);
            application.RecordBuild(secondVersionControlNumber);
            Assert.That(application.Version.ToString(), Is.EqualTo("0.0.1+2"));

            var secondInstanceOfVersionKeeper = new ApplicationVersionKeeper(stateStore);
            application = secondInstanceOfVersionKeeper.GetVersionedApplication(applicationName);
            
            Assert.That(application.Version.ToString(), Is.EqualTo("0.0.1+2"));
        }