Skip to content
This repository has been archived by the owner on Sep 19, 2019. It is now read-only.

SimpleTwitter web application #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1,030 changes: 1,030 additions & 0 deletions .vs/config/applicationhost.config

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions ReadMe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Simple Twitter

I deployed MongoDB Compass (cloud version) on AWS however I was not able to successfully connect to it. Therefore, the solution requires that
the machine that runs the web app has MongoDB installed.
34 changes: 34 additions & 0 deletions Simple Twitter.Tests/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Note: Add entries to the App.config file for configuration settings
that apply only to the Test project.
-->
<configuration>
<appSettings>

</appSettings>

<connectionStrings>

</connectionStrings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.1" newVersion="4.0.2.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
91 changes: 91 additions & 0 deletions Simple Twitter.Tests/Controllers/SimpleTwitterControllerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Simple_Twitter.Utilities;
using Simple_Twitter.Controllers;
using Moq;

namespace Simple_Twitter.Tests.Controllers
{
[TestClass]
public class SimpleTwitterControllerTest
{
[TestMethod]
public void Index()
{
Mock<IDBConfig> dbConfig = new Mock<IDBConfig>();
dbConfig.Setup(x => x.GetDBHost()).Returns("mongodb://127.0.0.1:27017");
dbConfig.Setup(x => x.GetDBName()).Returns("SimpleTwitterDB");
SimpleTwitterController controller = new SimpleTwitterController(dbConfig.Object);

// Test null strings
string handle = null;
string tweet = null;
ViewResult result = controller.Index(handle, tweet) as ViewResult;
Assert.IsNull(result.ViewBag.Handle);
Assert.IsNull(result.ViewBag.Tweet);

//Test empty strings
handle = "";
tweet = "";
result = controller.Index(handle, tweet) as ViewResult;
Assert.IsNull(result.ViewBag.Handle);
Assert.IsNull(result.ViewBag.Tweet);

//Test large tweet
handle = "@user";
tweet = "asdkfja;skldfjalskdfjas;lkdjfsalkdfjslk;dfjaslk;dfjsakd;lfjsal;kdfjslkdfjskldfjsdlkjasldkjdsalkfj" +
"aslkdfjsal;kdfjasl;kdjfl;aksdjfl;aksdjfaksdfklasjdfklasjdflkasjdfl;kasjdflkasjdflkasjdflkdfjasld;kfjasdlk" +
"asdlfjsadlkfjasdl;kfjasdlkfjsadlkfjasdlkfjasldkfjaslkd;fjasl;kdfjaskdlfjasldkfjsldkfjslkdfjaslkdfjasldk";
result = controller.Index(handle, tweet) as ViewResult;
Assert.IsNull(result.ViewBag.Handle);
Assert.IsNull(result.ViewBag.Tweet);

//Test Valid Tweet
handle = "@user";
tweet = "hello... I'm tweeting";
result = controller.Index(handle, tweet) as ViewResult;
Assert.IsNotNull(result.ViewBag.Handle);
Assert.IsNotNull(result.ViewBag.Tweet);
}

[TestMethod]
public void ViewTweets()
{
Mock<IDBConfig> dbConfig = new Mock<IDBConfig>();
dbConfig.Setup(x => x.GetDBHost()).Returns("mongodb://127.0.0.1:27017");
dbConfig.Setup(x => x.GetDBName()).Returns("SimpleTwitterDB");
SimpleTwitterController controller = new SimpleTwitterController(dbConfig.Object);

// Test null string
string handle = null;
ViewResult result = controller.ViewTweets(handle) as ViewResult;
Assert.IsNull(result.ViewBag.Handle);

//Test empty strings
handle = "";
result = controller.ViewTweets(handle) as ViewResult;
Assert.IsNull(result.ViewBag.Handle);

//Test Valid Tweet
handle = "@user";
string tweet = "hello... I'm tweeting";
controller.Index(handle, tweet);
result = controller.ViewTweets(handle) as ViewResult;

bool bFound = false;
foreach (var str in result.ViewBag.Tweets)
{
if (str.Tweet == tweet)
{
bFound = true;
break;
}
}
Assert.IsTrue(bFound);
}
}
}
35 changes: 35 additions & 0 deletions Simple Twitter.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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("Simple_Twitter.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Simple_Twitter.Tests")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[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("eea6321c-6266-4803-bf41-fb69c42d0381")]

// 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 Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
155 changes: 155 additions & 0 deletions Simple Twitter.Tests/Simple Twitter.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{998DDFD8-B7FB-46E9-B9E2-07BB57D9D2BC}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Simple_Twitter.Tests</RootNamespace>
<AssemblyName>Simple Twitter.Tests</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</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="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Core.4.3.1\lib\net45\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="DnsClient, Version=1.0.7.0, Culture=neutral, PublicKeyToken=4574bb5573c51424, processorArchitecture=MSIL">
<HintPath>..\packages\DnsClient.1.0.7\lib\net45\DnsClient.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework">
<HintPath>..\packages\MSTest.TestFramework.1.2.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions">
<HintPath>..\packages\MSTest.TestFramework.1.2.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Bson, Version=2.7.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Bson.2.7.0\lib\net45\MongoDB.Bson.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Driver, Version=2.7.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Driver.2.7.0\lib\net45\MongoDB.Driver.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Driver.Core, Version=2.7.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Driver.Core.2.7.0\lib\net45\MongoDB.Driver.Core.dll</HintPath>
</Reference>
<Reference Include="Moq, Version=4.9.0.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.9.0\lib\net45\Moq.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.3.0\lib\netstandard1.1\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.0.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.3.0\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\net461\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Web" />
<Reference Include="System.Web.ApplicationServices" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Web.Abstractions" />
<Reference Include="System.Web.Routing" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.11.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.4\lib\net45\System.Web.Helpers.dll</HintPath>
</Reference>
<Reference Include="System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.Mvc.5.2.4\lib\net45\System.Web.Mvc.dll</HintPath>
</Reference>
<Reference Include="System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.Razor.3.2.4\lib\net45\System.Web.Razor.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.4\lib\net45\System.Web.WebPages.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages.Deployment, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.4\lib\net45\System.Web.WebPages.Deployment.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.4\lib\net45\System.Web.WebPages.Razor.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Controllers\SimpleTwitterControllerTest.cs" />
<Compile Include="Utilities\ElapsedTimeStringTest.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="App.config" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Simple Twitter\Simple Twitter.csproj">
<Project>{25DD403E-F29B-415F-BAEF-95544C33C7C6}</Project>
<Name>Simple Twitter</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.targets'))" />
</Target>
<Import Project="..\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.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>
55 changes: 55 additions & 0 deletions Simple Twitter.Tests/Utilities/ElapsedTimeStringTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Simple_Twitter.Utilities;

namespace Simple_Twitter.Tests.Utilities
{
[TestClass]
public class ElapsedTimeStringTest
{
[TestMethod]
public void GetElaspedTimeString()
{
DateTime fortyFiveMinsAgo = DateTime.Now.AddMinutes(-45);
string str = ElaspedTimeString.GetElaspedTimeString(fortyFiveMinsAgo);
Assert.AreEqual(str, "45 minutes ago");

DateTime oneMinuteAgo = DateTime.Now.AddMinutes(-1);
str = ElaspedTimeString.GetElaspedTimeString(oneMinuteAgo);
Assert.AreEqual(str, "1 minute ago");

DateTime tenSecondsAgo = DateTime.Now.AddSeconds(-10);
str = ElaspedTimeString.GetElaspedTimeString(tenSecondsAgo);
Assert.AreEqual(str, "10 seconds ago");

DateTime oneSecondAgo = DateTime.Now.AddSeconds(-1);
str = ElaspedTimeString.GetElaspedTimeString(oneSecondAgo);
Assert.AreEqual(str, "1 second ago");

DateTime fiveHoursAgo = DateTime.Now.AddHours(-5);
str = ElaspedTimeString.GetElaspedTimeString(fiveHoursAgo);
Assert.AreEqual(str, "5 hours ago");

DateTime oneHourAgo = DateTime.Now.AddHours(-1);
str = ElaspedTimeString.GetElaspedTimeString(oneHourAgo);
Assert.AreEqual(str, "1 hour ago");

DateTime fiveDaysAgo = DateTime.Now.AddDays(-5);
str = ElaspedTimeString.GetElaspedTimeString(fiveDaysAgo);
Assert.AreEqual(str, "5 days ago");

DateTime oneDayAgo = DateTime.Now.AddDays(-1);
str = ElaspedTimeString.GetElaspedTimeString(oneDayAgo);
Assert.AreEqual(str, "1 day ago");

DateTime twoYearsAgo = DateTime.Now.AddDays(-730);
str = ElaspedTimeString.GetElaspedTimeString(twoYearsAgo);
Assert.AreEqual(str, "2 years ago");

DateTime oneYearAgo = DateTime.Now.AddDays(-365);
str = ElaspedTimeString.GetElaspedTimeString(oneYearAgo);
Assert.AreEqual(str, "1 year ago");

}
}
}
Loading