Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 2e0706a0db67d9782c7ecae5e1e41c8ed0275ae8 @lennykean committed Feb 24, 2012
@@ -0,0 +1,43 @@
+using System.Collections.Generic;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+using NoteCards.DomainModel;
+using NoteCards.Presenter;
+using NoteCards.View;
+
+namespace NoteCards.Test
+{
+ [TestClass]
+ public class MainPresenterTests
+ {
+ [TestMethod]
+ public void LoadTest()
+ {
+ var notes = new[] {"Note1", "Note2"};
+ var repo = new Mock<INoteCardRepository>();
+ var view = new Mock<IMainView>();
+ repo.Setup(m => m.NoteCards)
+ .Returns(notes)
+ .Verifiable();
+
+ var presenter = new MainPresenter(view.Object, repo.Object);
+
+ repo.Verify();
+ view.Verify(m => m.LoadNotes(It.IsAny<IEnumerable<string>>()));
+ view.VerifySet(m => m.StatusText = "2 Notes");
+ }
+
+ [TestMethod]
+ public void NewNoteTest()
+ {
+ var repo = new Mock<INoteCardRepository>();
+ var view = new Mock<IMainView>();
+
+ var presenter = new MainPresenter(view.Object, repo.Object);
+ view.Raise(m => m.NewNote += null, null, null);
+
+ view.Verify(m => m.ClearSelectedNote());
+ view.Verify(m => m.LoadNote(It.IsAny<NoteCard>()));
+ }
+ }
+}
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>
+ </ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{BC0922E2-1886-405F-8CAE-9760187F6B3E}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>NoteCards.Test</RootNamespace>
+ <AssemblyName>NoteCards.Test</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
+ <Reference Include="Moq, Version=4.0.10827.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
+ <Private>True</Private>
+ <HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ </ItemGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="MainPresenterTests.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\NoteCards\NoteCards.csproj">
+ <Project>{0276A578-848C-4674-9C94-3B10DCFE82D6}</Project>
+ <Name>NoteCards</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="packages.config" />
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
@@ -0,0 +1,35 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("MvpDemo.Test")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("MvpDemo.Test")]
+[assembly: AssemblyCopyright("Copyright © 2012")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("1807cc73-92c4-4ad7-a259-c9a98e9d8fdc")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="Moq" version="4.0.10827" />
+</packages>
@@ -0,0 +1,42 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NoteCards", "NoteCards\NoteCards.csproj", "{0276A578-848C-4674-9C94-3B10DCFE82D6}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NoteCards.Test", "NoteCards.Test\NoteCards.Test.csproj", "{BC0922E2-1886-405F-8CAE-9760187F6B3E}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Debug|Mixed Platforms = Debug|Mixed Platforms
+ Debug|x86 = Debug|x86
+ Release|Any CPU = Release|Any CPU
+ Release|Mixed Platforms = Release|Mixed Platforms
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {0276A578-848C-4674-9C94-3B10DCFE82D6}.Debug|Any CPU.ActiveCfg = Debug|x86
+ {0276A578-848C-4674-9C94-3B10DCFE82D6}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
+ {0276A578-848C-4674-9C94-3B10DCFE82D6}.Debug|Mixed Platforms.Build.0 = Debug|x86
+ {0276A578-848C-4674-9C94-3B10DCFE82D6}.Debug|x86.ActiveCfg = Debug|x86
+ {0276A578-848C-4674-9C94-3B10DCFE82D6}.Debug|x86.Build.0 = Debug|x86
+ {0276A578-848C-4674-9C94-3B10DCFE82D6}.Release|Any CPU.ActiveCfg = Release|x86
+ {0276A578-848C-4674-9C94-3B10DCFE82D6}.Release|Mixed Platforms.ActiveCfg = Release|x86
+ {0276A578-848C-4674-9C94-3B10DCFE82D6}.Release|Mixed Platforms.Build.0 = Release|x86
+ {0276A578-848C-4674-9C94-3B10DCFE82D6}.Release|x86.ActiveCfg = Release|x86
+ {0276A578-848C-4674-9C94-3B10DCFE82D6}.Release|x86.Build.0 = Release|x86
+ {BC0922E2-1886-405F-8CAE-9760187F6B3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {BC0922E2-1886-405F-8CAE-9760187F6B3E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {BC0922E2-1886-405F-8CAE-9760187F6B3E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {BC0922E2-1886-405F-8CAE-9760187F6B3E}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {BC0922E2-1886-405F-8CAE-9760187F6B3E}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {BC0922E2-1886-405F-8CAE-9760187F6B3E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {BC0922E2-1886-405F-8CAE-9760187F6B3E}.Release|Any CPU.Build.0 = Release|Any CPU
+ {BC0922E2-1886-405F-8CAE-9760187F6B3E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {BC0922E2-1886-405F-8CAE-9760187F6B3E}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {BC0922E2-1886-405F-8CAE-9760187F6B3E}.Release|x86.ActiveCfg = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
@@ -0,0 +1,16 @@
+using System;
+using System.ComponentModel.DataAnnotations;
+
+namespace NoteCards.DomainModel
+{
+ public class NoteCard
+ {
+ [Required]
+ [RegularExpression(@"^[_0-9a-zA-Z\s\-_]+$", ErrorMessage="Title cannot contain special characters.")]
+ public string Title { get; set; }
+ [Required]
+ public string NoteText { get; set; }
+ public DateTime? CreateDate { get; set; }
+ public DateTime? EditDate { get; set; }
+ }
+}
@@ -0,0 +1,16 @@
+
+using System.Collections.Generic;
+using NoteCards.DomainModel;
+
+namespace NoteCards
+{
+ public interface INoteCardRepository
+ {
+ IEnumerable<string> NoteCards { get; }
+
+ NoteCard GetNote(string title);
+ bool NoteExists(string title);
+ void Save(NoteCard note);
+ void Delete(NoteCard note);
+ }
+}
@@ -0,0 +1,60 @@
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Windows.Forms;
+using NoteCards.DomainModel;
+
+namespace NoteCards
+{
+ public class NoteCardRepository : INoteCardRepository
+ {
+ private string BaseDirectory
+ {
+ get { return Path.GetDirectoryName(Application.ExecutablePath); }
+ }
+
+ public IEnumerable<string> NoteCards
+ {
+ get
+ {
+ return
+ from f in Directory.GetFiles(BaseDirectory, "*.note")
+ select Path.GetFileNameWithoutExtension(f);
+ }
+ }
+
+ public NoteCard GetNote(string title)
+ {
+ var file = Path.Combine(BaseDirectory, title + ".note");
+
+ return new NoteCard
+ {
+ Title = title,
+ NoteText = File.ReadAllText(file),
+ CreateDate = File.GetCreationTime(file),
+ EditDate = File.GetLastWriteTime(file)
+ };
+ }
+
+ public bool NoteExists(string title)
+ {
+ var file = Path.Combine(BaseDirectory, title + ".note");
+
+ return File.Exists(file);
+ }
+
+ public void Save(NoteCard note)
+ {
+ var file = Path.Combine(BaseDirectory, note.Title + ".note");
+
+ File.WriteAllText(file, note.NoteText);
+ }
+
+ public void Delete(NoteCard note)
+ {
+ var file = Path.Combine(BaseDirectory, note.Title + ".note");
+
+ File.Delete(file);
+ }
+ }
+}
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{0276A578-848C-4674-9C94-3B10DCFE82D6}</ProjectGuid>
+ <OutputType>WinExe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>NoteCards</RootNamespace>
+ <AssemblyName>NoteCards</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <TargetFrameworkProfile>
+ </TargetFrameworkProfile>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.ComponentModel.DataAnnotations" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Drawing" />
+ <Reference Include="System.Windows.Forms" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="DomainModel\NoteCard.cs" />
+ <Compile Include="INoteCardRepository.cs" />
+ <Compile Include="NoteCardRepository.cs" />
+ <Compile Include="Presenter\MainPresenter.cs" />
+ <Compile Include="View\IMainView.cs" />
+ <Compile Include="View\MainForm.cs">
+ <SubType>Form</SubType>
+ </Compile>
+ <Compile Include="View\MainForm.Designer.cs">
+ <DependentUpon>MainForm.cs</DependentUpon>
+ </Compile>
+ <Compile Include="Program.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <EmbeddedResource Include="View\MainForm.resx">
+ <DependentUpon>MainForm.cs</DependentUpon>
+ </EmbeddedResource>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
Oops, something went wrong.

0 comments on commit 2e0706a

Please sign in to comment.