You can use any object that implements the
To make a
It is also standard practice that at least one of your constructors takes an
A collection that contains no duplicate elements. This class models the mathematical
+
None of the
The following table summarizes the binary operators that are supported by the
A collection that contains no duplicate elements. This interface models the mathematical
+
None of the
The following table summarizes the binary operators that are supported by the
A collection that contains no duplicate elements. This interface models the mathematical
+
None of the
The following table summarizes the binary operators that are supported by the
Implements an immutable (read-only)
Although this is advertised as immutable, it really isn't. Anyone with access to the
+
Implements a thread-safe
You can use any object that implements the
To make a
It is also standard practice that at least one of your constructors takes an
Implements an immutable (read-only)
Although this is advertised as immutable, it really isn't. Anyone with access to the
+
+ Abstracts ADO.NET batching to maintain the illusion that a single logical batch
+ exists for the whole session, even when batching is disabled.
+ Provides transparent
+ This will be useful once ADO.NET gets support for batching. Until that point + no code exists that will do batching, but this will provide a good point to do + error checking and making sure the correct number of rows were affected. +
+
+ configuration.Configure("path/to/hibernate.cfg.xml");
+
+
+ If this ConnectionProvider is being Finalized (
+ If any subclasses manage resources that also need to be disposed of this method + should be overridden, but don't forget to call it in the override. +
+
+ List results = session.CreateCriteria(typeof(Parent))
+ .Add( Example.Create(parent).IgnoreCase() )
+ .CreateCriteria("child")
+ .Add( Example.Create( parent.Child ) )
+ .List();
+
+ concat(?1, ?2)
to concatenate two strings
+ p1 and p2. Target SQL function will be dialect-specific, e.g. (?1 || ?2)
for
+ Oracle, concat(?1, ?2)
for MySql, (?1 + ?2)
for MS SQL.
+ Each dialect will define a template as a string (exactly like above) marking function
+ parameters with '?' followed by parameter's index (first index is 1).
+
+ This method assumes that the name is not already Quoted. So if the name passed
+ in is
+ If the aliasName is already enclosed in the OpenQuote and CloseQuote then this + method will return the aliasName that was passed in without going through any + Quoting process. So if aliasName is passed in already Quoted make sure that + you have escaped all of the chars according to your DataBase's specifications. +
++ If the columnName is already enclosed in the OpenQuote and CloseQuote then this + method will return the columnName that was passed in without going through any + Quoting process. So if columnName is passed in already Quoted make sure that + you have escaped all of the chars according to your DataBase's specifications. +
++ If the tableName is already enclosed in the OpenQuote and CloseQuote then this + method will return the tableName that was passed in without going through any + Quoting process. So if tableName is passed in already Quoted make sure that + you have escaped all of the chars according to your DataBase's specifications. +
++ If the schemaName is already enclosed in the OpenQuote and CloseQuote then this + method will return the schemaName that was passed in without going through any + Quoting process. So if schemaName is passed in already Quoted make sure that + you have escaped all of the chars according to your DataBase's specifications. +
+
+ This method checks the string
+ After the OpenQuote and CloseQuote have been cleaned from the string
+ The following quoted values return these results + "quoted" = quoted + "quote""d" = quote"d + quote""d = quote"d +
++ If this implementation is not sufficient for your Dialect then it needs to be overridden. + MsSql2000Dialect is an example of where UnQuoting rules are different. +
+
+
+ SELECT
+ TOP last (columns)
+ FROM
+ (SELECT (columns), ROW_NUMBER() OVER(ORDER BY {original order by, with un-aliased column names) as __hibernate_sort_row
+ {original from}) as query
+ WHERE query.__hibernate_sort_row > offset
+ ORDER BY query.__hibernate_sort_row
+
+
+
+ Note that we need to add explicitly specify the columns, because we need to be able to use them
+ in a paged subselect. NH-1155
+ + Author: Ioan Bizau +
++ This dialect probably will not work with schema-export. If anyone out there + can fill in the ctor with DbTypes to Strings that would be helpful. +
+ The SybaseDialect defaults the following configuration properties: ++ This dialect probably will not work with schema-export. If anyone out there + can fill in the ctor with DbTypes to Strings that would be helpful. +
+ The SybaseDialect defaults the following configuration properties: ++ This dialect probably will not work with schema-export. If anyone out there + can fill in the ctor with DbTypes to Strings that would be helpful. +
+ The SybaseAnywhereDialect defaults the following configuration properties: +
+ Names.Put(DbType, "TEXT" );
+ Names.Put(DbType, 255, "VARCHAR($l)" );
+ Names.Put(DbType, 65534, "LONGVARCHAR($l)" );
+
+ will give you back the following:
+
+ Names.Get(DbType) // --> "TEXT" (default)
+ Names.Get(DbType,100) // --> "VARCHAR(100)" (100 is in [0:255])
+ Names.Get(DbType,1000) // --> "LONGVARCHAR(1000)" (100 is in [256:65534])
+ Names.Get(DbType,100000) // --> "TEXT" (default)
+
+ On the other hand, simply putting
+
+ Names.Put(DbType, "VARCHAR($l)" );
+
+ would result in
+
+ Names.Get(DbType) // --> "VARCHAR($l)" (will cause trouble)
+ Names.Get(DbType,100) // --> "VARCHAR(100)"
+ Names.Get(DbType,1000) // --> "VARCHAR(1000)"
+ Names.Get(DbType,10000) // --> "VARCHAR(10000)"
+
+
+ key="connection.driver_class"
+ value="FullyQualifiedClassName, AssemblyName"
+
+ IDbParameter param = cmd.Parameters["@paramName"]
+ if this is false the code will be
+ IDbParameter param = cmd.Parameters["paramName"]
.
+ + Author: Oliver Weichhold +
++ In order to use this Driver you must have the Npgsql.dll Assembly available for + NHibernate to load it. +
++ Please check the products website + http://www.postgresql.org/ + for any updates and or documentation. +
++ The homepage for the .NET DataProvider is: + http://pgfoundry.org/projects/npgsql. +
++ In order to use this driver you must have the System.Data.SQLite.dll assembly available + for NHibernate to load. This assembly includes the SQLite.dll or SQLite3.dll libraries. +
++ You can get the System.Data.SQLite.dll assembly from http://sourceforge.net/projects/sqlite-dotnet2. +
++ Please check http://www.sqlite.org/ for more information regarding SQLite. +
++ Author: Ioan Bizau +
++ In order to use this Driver you must have the SQLite.NET.dll Assembly available for NHibernate to load it. + You must also have the SQLite.dll and SQLite3.dll libraries. +
++ Please check http://www.sqlite.org/ for more information regarding SQLite. +
+
+ ISession sess = factory.OpenSession();
+ ITransaction tx;
+ try {
+ tx = sess.BeginTransaction();
+ //do some work
+ ...
+ tx.Commit();
+ } catch (Exception e) {
+ if (tx != null) tx.Rollback();
+ throw;
+ } finally {
+ sess.Close();
+ }
+
+
+ This class implements useful common functionality that concrete loaders would delegate to.
+ It is not intended that this functionality would be directly accessed by client code (Hence,
+ all methods of this class are declared
+ The present implementation is able to load any number of columns of entities and at most + one collection role per query. +
+
+ This id generation strategy is specified in the mapping file as
+ <generator class="assigned" />
+
+ <generator class="foreign">
+ <param name="property">AssociatedObject</param>
+ </generator>
+
+
+ This id generation strategy is specified in the mapping file as
+ <generator class="guid.comb" />
+
+ The
+ This code was contributed by Donald Mull. +
+
+ This id generation strategy is specified in the mapping file as
+ <generator class="guid" />
+
The built in strategies for identifier generation in NHibernate are:
+
+ This id generation strategy is specified in the mapping file as
+ <generator class="identity" />
+ or if the database natively supports identity columns
+ <generator class="native" />
+
+ This indicates to NHibernate that the database generates the id when + the entity is inserted. +
+
+ This id generation strategy is specified in the mapping file as
+
+ <generator class="sequence">
+ <param name="sequence">uid_sequence</param>
+ <param name="schema">db_schema</param>
+ </generator>
+
+
+ The
+ This id generation strategy is specified in the mapping file as
+
+ <generator class="seqhilo">
+ <param name="sequence">uid_sequence</param>
+ <param name="max_lo">max_lo_value</param>
+ <param name="schema">db_schema</param>
+ </generator>
+
+
+ The
+ The user may specify a
+ It is not intended that applications use this strategy directly. However,
+ it may be used to build other (efficient) strategies. The return type is
+
+ The hi value MUST be fetched in a seperate transaction to the
+ The mapping parameters
+ This id generation strategy is specified in the mapping file as
+
+ <generator class="hilo">
+ <param name="table">table</param>
+ <param name="column">id_column</param>
+ <param name="max_lo">max_lo_value</param>
+ <param name="schema">db_schema</param>
+ </generator>
+
+
+ The
+ The hi value MUST be fecthed in a seperate transaction to the
+ This id generation strategy is specified in the mapping file as
+
+ <generator class="uuid.hex">
+ <param name="format">format_string</param>
+ <param name="seperator">seperator_string</param>
+ </generator>
+
+
+ The
+ The identifier string will consist of only hex digits. Optionally, the identifier string + may be generated with enclosing characters and seperators between each component + of the UUID. If there are seperators then the string length will be 36. If a format + that has enclosing brackets is used, then the string length will be 38. +
+
+
+
+ This class is based on
+ This id generation strategy is specified in the mapping file as
+ <generator class="uuid.string" />
+
+ SetParameter("foo", foo, NHibernateUtil.Int32);
+
+ for example. A name may appear multiple times in the query string.
+ + Entities returned as results are initialized on demand. The first SQL query returns + identifiers only. +
+
+ This is a good strategy to use if you expect a high number of the objects
+ returned to be already loaded in the
+ IList cats = session.CreateCriteria(typeof(Cat))
+ .Add( Expression.Like("name", "Iz%") )
+ .Add( Expression.Gt( "weight", minWeight ) )
+ .AddOrder( Order.Asc("age") )
+ .List();
+
+ You may navigate associations using
+ IList cats = session.CreateCriteria(typeof(Cat))
+ .CreateCriteria("kittens")
+ .Add( Expression.like("name", "Iz%") )
+ .List();
+
+
+ IList cats = session.CreateCriteria(typeof(Cat))
+ .setProjection( Projections.ProjectionList()
+ .Add( Projections.RowCount() )
+ .Add( Projections.Avg("weight") )
+ .Add( Projections.Max("weight") )
+ .Add( Projections.Min("weight") )
+ .Add( Projections.GroupProperty("color") )
+ )
+ .AddOrder( Order.Asc("color") )
+ .List();
+
+
+ <sql-query-name name="mySqlQuery">
+ <return alias="person" class="eg.Person" />
+ SELECT {person}.NAME AS {person.name}, {person}.AGE AS {person.age}, {person}.SEX AS {person.sex}
+ FROM PERSON {person} WHERE {person}.NAME LIKE 'Hiber%'
+ </sql-query-name>
+
+
+ If a value is passed in that is wrapped by
+ The value returned by the getter is not Quoted. To get the
+ column name in quoted form use
+ If a value is passed in that is wrapped by
+ The value returned by the getter is not Quoted. To get the
+ column name in quoted form use
case when ... then ... end as ...
+ decode(pkvalue, key1, 1, key2, 2, ..., 0)
+
+ The
+ The
+ This can store the length of the binary data that the
+ This is only needed by DataProviders (SqlClient) that need to specify a Size for the + IDbDataParameter. Most DataProvider(Oralce) don't need to set the Size so a + BinarySqlType would work just fine. +
+
+ This can store the length of the binary data that the
+ This is only needed by DataProviders (SqlClient) that need to specify a Size for the + IDbDataParameter. Most DataProvider(Oralce) don't need to set the Size so a + StringSqlType would work just fine. +
+
+ IList resultWithAliasedBean = s.CreateCriteria(typeof(Enrollment))
+ .CreateAlias("Student", "st")
+ .CreateAlias("Course", "co")
+ .SetProjection( Projections.ProjectionList()
+ .Add( Projections.Property("co.Description"), "CourseDescription" )
+ )
+ .SetResultTransformer( new AliasToBeanResultTransformer(typeof(StudentDTO)) )
+ .List();
+
+ StudentDTO dto = (StudentDTO)resultWithAliasedBean[0];
+
+ + The value stored in the database depends on what your data provider is capable + of storing. So there is a possibility that the DateTime you save will not be + the same DateTime you get back when you check DateTime.Equals(DateTime) because + they will have their milliseconds off. +
+
+ For example - SQL Server 2000 is only accurate to 3.33 milliseconds. So if
+ NHibernate writes a value of
+ Please review the documentation of your Database server. +
+
+ public enum MyEnum
+ {
+ On,
+ Off,
+ Dimmed
+ }
+
+
+
+ public class MyEnumStringType : NHibernate.Type.EnumStringType
+ {
+ public MyEnumStringType()
+ : base( typeof( MyEnum ) )
+ {
+ }
+ }
+
+
+
+ ...
+ <property name="Status" type="MyEnumStringType, AssemblyContaining" />
+ ...
+
+
+ 'T'/'F'
to indicate true/false
.
+ 'Y'/'N'
to indicate true/false
.
+ any
.
+
+ CREATE TABLE [dbo].[Log] (
+ [ID] [int] IDENTITY (1, 1) NOT NULL ,
+ [Date] [datetime] NOT NULL ,
+ [Thread] [varchar] (255) NOT NULL ,
+ [Level] [varchar] (20) NOT NULL ,
+ [Logger] [varchar] (255) NOT NULL ,
+ [Message] [varchar] (4000) NOT NULL
+ ) ON [PRIMARY]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "DSN=MS Access Database;UID=admin;PWD=;SystemDB=C:\data\System.mdw;SafeTransactions = 0;FIL=MS Access;DriverID = 25;DBQ=C:\data\train33.mdb"
+ "Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\Work\cvs_root\log4net-1.2\access.mdb;UID=;PWD=;"
+ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Work\cvs_root\log4net-1.2\access.mdb;User Id=;Password=;"
+ System.Data.OleDb.OleDbConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+ System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+ Microsoft.Data.Odbc.OdbcConnection,Microsoft.Data.Odbc,version=1.0.3300.0,publicKeyToken=b77a5c561934e089,culture=neutral
+ This is an optional package that you can download from
+ http://msdn.microsoft.com/downloads
+ search for ODBC .NET Data Provider.
+ System.Data.OracleClient.OracleConnection, System.Data.OracleClient, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+ This is an optional package that you can download from
+ http://msdn.microsoft.com/downloads
+ search for .NET Managed Provider for Oracle.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <mapping>
+ <level value="ERROR" />
+ <eventLogEntryType value="Error" />
+ </mapping>
+ <mapping>
+ <level value="DEBUG" />
+ <eventLogEntryType value="Information" />
+ </mapping>
+
+
+
+
+
+
+
+
+
+ IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
+ UdpClient udpClient;
+ byte[] buffer;
+ string loggingEvent;
+
+ try
+ {
+ udpClient = new UdpClient(8080);
+
+ while(true)
+ {
+ buffer = udpClient.Receive(ref remoteEndPoint);
+ loggingEvent = System.Text.Encoding.Unicode.GetString(buffer);
+ Console.WriteLine(loggingEvent);
+ }
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine(e.ToString());
+ }
+
+
+ Dim remoteEndPoint as IPEndPoint
+ Dim udpClient as UdpClient
+ Dim buffer as Byte()
+ Dim loggingEvent as String
+
+ Try
+ remoteEndPoint = new IPEndPoint(IPAddress.Any, 0)
+ udpClient = new UdpClient(8080)
+
+ While True
+ buffer = udpClient.Receive(ByRef remoteEndPoint)
+ loggingEvent = System.Text.Encoding.Unicode.GetString(buffer)
+ Console.WriteLine(loggingEvent)
+ Wend
+ Catch e As Exception
+ Console.WriteLine(e.ToString())
+ End Try
+
+
+
+
+
+
+
+
+
+ using log4net.Config;
+ using System.IO;
+ using System.Configuration;
+
+ ...
+
+ DOMConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
+
+
+
+
+
+
+
+
+
+ using log4net.Config;
+ using System.IO;
+ using System.Configuration;
+
+ ...
+
+ DOMConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ log4net configuration XML goes here
+
+
+
+
+
+
+
+
+
+ using log4net.Config;
+ using System.IO;
+ using System.Configuration;
+
+ ...
+
+ XmlConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ using log4net.Config;
+ using System.IO;
+ using System.Configuration;
+
+ ...
+
+ XmlConfigurator.Configure(new FileInfo(ConfigurationSettings.AppSettings["log4net-config-file"]));
+
+
+
+
+
+
+
+
+
+ ILog log = LogManager.GetLogger("application-log");
+
+ log.Info("Application Start");
+ log.Debug("This is a debug message");
+
+ if (log.IsDebugEnabled)
+ {
+ log.Debug("This is another debug message");
+ }
+
+
+ log.Debug("This is entry number: " + i );
+
+
+ if (log.IsDebugEnabled)
+ {
+ log.Debug("This is entry number: " + i );
+ }
+
+
+ private static readonly bool isDebugEnabled = log.IsDebugEnabled;
+
+
+ if (isDebugEnabled)
+ {
+ log.Debug("This is entry number: " + i );
+ }
+
+
+ log.Debug("This is entry number: " + i );
+
+
+ if (log.IsDebugEnabled())
+ {
+ log.Debug("This is entry number: " + i );
+ }
+
+
+ {key1=value1, key2=value2, key3=value3}
+
+
+ StringWriter writer = new StringWriter();
+ Layout.Format(writer, loggingEvent);
+ string formattedEvent = writer.ToString();
+
+
+ ILog log = LogManager.GetLogger(typeof(TestApp));
+ log.Debug("Message 1");
+ log.Warn("Message 2");
+
+
+ DEBUG [main]: Message 1
+ WARN [main]: Message 2
+
+ Format modifier | +left justify | +minimum width | +maximum width | +comment | +
---|---|---|---|---|
%20logger | +false | +20 | +none | +
+ |
+
%-20logger | +true | +20 | +none | +
+ |
+
%.30logger | +NA | +none | +30 | +
+ |
+
false | +20 | +30 | +
+ |
+ |
%-20.30logger | +true | +20 | +30 | +
+ |
+
%timestamp [%thread] %level %logger %ndc - %message%newline
+ %-6timestamp [%15.15thread] %-5level %30.30logger %ndc - %message%newline
+
+ DEBUG - Hello world
+
+
+ <?xml version="1.0" ?>
+
+ <!DOCTYPE log4net:events SYSTEM "log4net-events.dtd" [<!ENTITY data SYSTEM "abc">]>
+
+ <log4net:events version="1.2" xmlns:log4net="http://logging.apache.org/log4net/schemas/log4net-events-1.2>
+ &data;
+ </log4net:events>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ string s = OptionConverter.SubstituteVariables("Value of key is ${key}.");
+
+
+ string s = OptionConverter.SubstituteVariables("Value of nonExistentKey is [${nonExistentKey}]");
+
+
+ using(log4net.ThreadContext.Stacks["NDC"].Push("Stack_Message"))
+ {
+ log.Warn("This should have an ThreadContext Stack message");
+ }
+
+
+ GlobalContext.Properties["hostname"] = Environment.MachineName;
+
+
+ LogicalThreadContext.Properties["user"] = userName;
+ log.Info("This log message has a LogicalThreadContext Property called 'user'");
+
+
+ using(LogicalThreadContext.Stacks["LDC"].Push("my context message"))
+ {
+ log.Info("This log message has a LogicalThreadContext Stack message that includes 'my context message'");
+
+ } // at the end of the using block the message is automatically popped
+
+
+ ILog log = LogManager.GetLogger("application-log");
+
+ log.Info("Application Start");
+ log.Debug("This is a debug message");
+
+ if (log.IsDebugEnabled)
+ {
+ log.Debug("This is another debug message");
+ }
+
+
+ using(NDC.Push("my context message"))
+ {
+ ... all log calls will have 'my context message' included ...
+
+ } // at the end of the using block the message is automatically removed
+
+
+ using(log4net.NDC.Push("NDC_Message"))
+ {
+ log.Warn("This should have an NDC message");
+ }
+
+
+ ThreadContext.Properties["user"] = userName;
+ log.Info("This log message has a ThreadContext Property called 'user'");
+
+
+ using(ThreadContext.Stacks["NDC"].Push("my context message"))
+ {
+ log.Info("This log message has a ThreadContext Stack message that includes 'my context message'");
+
+ } // at the end of the using block the message is automatically popped
+
+ null
+ If the object is null
then an null
+ If the object is null
then an null
+ If the object is null
then an null
+ If the object is null
then an null
+ If the object is null
then an null
+ If the object is null
then an null
+ If the object is not null
then an null
+ If the object is not null
then an null
+ If the object is not null
then an null
+ If the object is not null
then an null
+ If the object is not null
then an null
+ If the object is not null
then an NaN
value.
+ If the object is not NaN
then an NaN
value.
+ If the object is not NaN
then an NaN
value.
+ If the object is not NaN
then an NaN
value.
+ If the object is not NaN
then an NaN
value.
+ If the object is not NaN
then an NaN
value.
+ If the object is not NaN
then an { + private readonly Iesi.Collections.Generic.ISetvotes = new HashedSet (); + private readonly Iesi.Collections.Generic.ISet flags = new HashedSet (); + + public virtual User Creator { get; set; } + public virtual DateTime Created { get; set; } + public virtual DateTime? Modified { get; set; } + + public virtual string Text { get; set; } + public virtual Game Game { get; set; } + + public virtual IEnumerable Votes { get { return votes; } } + public virtual IEnumerable Flags { get { return flags; } } + + public virtual void VoteFor(User user, VoteDirection direction) { + var currentVote = votes.SingleOrDefault(vote => vote.Voter == user); + if (currentVote != null) { + if (currentVote.Direction == direction) { + throw new CannotVoteTwiceException(); + } + + votes.Remove(currentVote); + currentVote.Direction = direction; + votes.Add(currentVote); + } else { + votes.Add(new Vote { Direction = direction, Quote = this, Voter = user }); + } + } + + public virtual int UpVotes { get { return Votes.Count(vote => vote.Direction == VoteDirection.Up); } } + public virtual int DownVotes { get { return Votes.Count(vote => vote.Direction == VoteDirection.Down); } } + public virtual int NetVotes { get { return Votes.Sum(vote => (int)vote); } } + } +} diff --git a/Src/VideoGameQuotes.Api/QuoteFlag.cs b/Src/VideoGameQuotes.Api/QuoteFlag.cs new file mode 100644 index 0000000..6a007a5 --- /dev/null +++ b/Src/VideoGameQuotes.Api/QuoteFlag.cs @@ -0,0 +1,11 @@ +using System; +using Portoa.Persistence; + +namespace VideoGameQuotes.Api { + public class QuoteFlag : Entity { + public virtual User User { get; set; } + public virtual Quote Quote { get; set; } + public virtual DateTime Created { get; set; } + public virtual string Comment { get; set; } + } +} \ No newline at end of file diff --git a/Src/VideoGameQuotes.Api/Region.cs b/Src/VideoGameQuotes.Api/Region.cs new file mode 100644 index 0000000..b57f5fc --- /dev/null +++ b/Src/VideoGameQuotes.Api/Region.cs @@ -0,0 +1,12 @@ +namespace VideoGameQuotes.Api { + /// + /// The region for which a game is associated + /// + public enum Region { + Unknown = 0, + UnitedStates = 1, + Japan = 2, + Europe = 3, + Other = 4 + } +} \ No newline at end of file diff --git a/Src/VideoGameQuotes.Api/System.cs b/Src/VideoGameQuotes.Api/System.cs new file mode 100644 index 0000000..6373781 --- /dev/null +++ b/Src/VideoGameQuotes.Api/System.cs @@ -0,0 +1,11 @@ +using System; +using Portoa.Persistence; + +namespace VideoGameQuotes.Api { + public class System : Entity{ + public virtual DateTime Created { get; set; } + public virtual DateTime ReleaseDate { get; set; } + public virtual string Name { get; set; } + public virtual string Abbreviation { get; set; } + } +} \ No newline at end of file diff --git a/Src/VideoGameQuotes.Api/User.cs b/Src/VideoGameQuotes.Api/User.cs new file mode 100644 index 0000000..e86906a --- /dev/null +++ b/Src/VideoGameQuotes.Api/User.cs @@ -0,0 +1,22 @@ +using System; +using Portoa.Logging; +using Portoa.Persistence; +using Portoa.Security; + +namespace VideoGameQuotes.Api { + public class User : Entity , IPasswordProtected { + private readonly IPasswordProtected passwordProtector = new NullAllowingPasswordProtector(); + + public virtual DateTime Created { get; set; } + public virtual string Username { get; set; } + public virtual UserGroup Group { get; set; } + + public virtual void ChangePassword([DoNotLog]string newPassword) { + passwordProtector.ChangePassword(newPassword); + } + + public virtual bool VerifyPassword([DoNotLog]string potentialPassword) { + return passwordProtector.VerifyPassword(potentialPassword); + } + } +} \ No newline at end of file diff --git a/Src/VideoGameQuotes.Api/UserGroup.cs b/Src/VideoGameQuotes.Api/UserGroup.cs new file mode 100644 index 0000000..cf7368a --- /dev/null +++ b/Src/VideoGameQuotes.Api/UserGroup.cs @@ -0,0 +1,7 @@ +namespace VideoGameQuotes.Api { + public enum UserGroup { + User = 1, + Moderator = 2, + Admin = 3 + } +} \ No newline at end of file diff --git a/Src/VideoGameQuotes.Api/VideoGameQuotes.Api.csproj b/Src/VideoGameQuotes.Api/VideoGameQuotes.Api.csproj new file mode 100644 index 0000000..f93bba5 --- /dev/null +++ b/Src/VideoGameQuotes.Api/VideoGameQuotes.Api.csproj @@ -0,0 +1,98 @@ + + + \ No newline at end of file diff --git a/Src/VideoGameQuotes.Api/Vote.cs b/Src/VideoGameQuotes.Api/Vote.cs new file mode 100644 index 0000000..b9a6b08 --- /dev/null +++ b/Src/VideoGameQuotes.Api/Vote.cs @@ -0,0 +1,15 @@ +using System; +using Portoa.Persistence; + +namespace VideoGameQuotes.Api { + public class Vote : Entity+ +Debug +AnyCPU +8.0.30703 +2.0 +{329FAB1F-A18D-4B7B-9E3C-A0C157E55503} +Library +Properties +VideoGameQuotes.Api +VideoGameQuotes.Api +v4.0 +512 ++ +true +full +false +..\..\bin\Debug\ +DEBUG;TRACE +prompt +4 ++ +pdbonly +true +..\..\bin\Release\ +TRACE +prompt +4 ++ ++ +..\..\Lib\Iesi.Collections.dll ++ +..\..\Lib\log4net.dll ++ +..\..\Lib\MySql.Data.dll ++ +..\..\Lib\NHibernate.dll ++ +..\..\Lib\NHibernate.Linq.dll ++ +..\..\Lib\Portoa.dll ++ +..\..\Lib\Portoa.NHibernate.dll ++ + + + + + + + ++ + + + + + + + + + + + + ++ + + + + + ++ + ++ + + { + public virtual User Voter { get; set; } + public virtual Quote Quote { get; set; } + public virtual DateTime Created { get; set; } + public virtual VoteDirection Direction { get; set; } + + public static explicit operator int(Vote vote) { + return vote.Direction == VoteDirection.Up ? 1 : -1; + } + } +} \ No newline at end of file diff --git a/Src/VideoGameQuotes.Api/VoteDirection.cs b/Src/VideoGameQuotes.Api/VoteDirection.cs new file mode 100644 index 0000000..7fdedab --- /dev/null +++ b/Src/VideoGameQuotes.Api/VoteDirection.cs @@ -0,0 +1,6 @@ +namespace VideoGameQuotes.Api { + public enum VoteDirection { + Up = 1, + Down = 0 + } +} \ No newline at end of file diff --git a/Tests/VideoGameQuotes.Api.Tests/NHibernate/SchemaExporter.cs b/Tests/VideoGameQuotes.Api.Tests/NHibernate/SchemaExporter.cs new file mode 100644 index 0000000..68390d6 --- /dev/null +++ b/Tests/VideoGameQuotes.Api.Tests/NHibernate/SchemaExporter.cs @@ -0,0 +1,19 @@ +using NHibernate.Cfg; +using NHibernate.Tool.hbm2ddl; +using NUnit.Framework; + +namespace VideoGameQuotes.Api.Tests.NHibernate { + [TestFixture] + public class SchemaExporter { + + [Test] + public void Export_schema() { + var config = new Configuration(); + config.Configure(GetType().Assembly, GetType().Namespace + ".hibernate.cfg.xml"); + new SchemaExport(config) + //.SetOutputFile(@"c:\users\tmont\code\VideoGameQuotes\schema.sql") + .Execute(true, true, false); + } + + } +} \ No newline at end of file diff --git a/Tests/VideoGameQuotes.Api.Tests/NHibernate/hibernate.cfg.xml b/Tests/VideoGameQuotes.Api.Tests/NHibernate/hibernate.cfg.xml new file mode 100644 index 0000000..a5d62f9 --- /dev/null +++ b/Tests/VideoGameQuotes.Api.Tests/NHibernate/hibernate.cfg.xml @@ -0,0 +1,13 @@ + + + + \ No newline at end of file diff --git a/Tests/VideoGameQuotes.Api.Tests/Properties/AssemblyInfo.cs b/Tests/VideoGameQuotes.Api.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..09e26f7 --- /dev/null +++ b/Tests/VideoGameQuotes.Api.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +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("VideoGameQuotes.Api.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("VideoGameQuotes.Api.Tests")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2011")] +[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("2442e9c9-ae50-441f-8f91-ebef6e3731d0")] + +// 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.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Tests/VideoGameQuotes.Api.Tests/QuoteTests.cs b/Tests/VideoGameQuotes.Api.Tests/QuoteTests.cs new file mode 100644 index 0000000..6f809ab --- /dev/null +++ b/Tests/VideoGameQuotes.Api.Tests/QuoteTests.cs @@ -0,0 +1,36 @@ +using NUnit.Framework; + +namespace VideoGameQuotes.Api.Tests { + [TestFixture] + public class QuoteTests { + + [Test] + [ExpectedException(typeof(CannotVoteTwiceException))] + public void Should_not_allow_voting_in_the_same_direction_twice() { + var quote = new Quote(); + var user = new User(); + + quote.VoteFor(user, VoteDirection.Up); + quote.VoteFor(user, VoteDirection.Up); + } + + [Test] + public void Should_remove_old_vote_if_voting_in_opposite_direction() { + var quote = new Quote(); + var user = new User(); + + quote.VoteFor(user, VoteDirection.Up); + + Assert.That(quote.UpVotes, Is.EqualTo(1)); + Assert.That(quote.DownVotes, Is.EqualTo(0)); + Assert.That(quote.NetVotes, Is.EqualTo(1)); + + quote.VoteFor(user, VoteDirection.Down); + + Assert.That(quote.UpVotes, Is.EqualTo(0)); + Assert.That(quote.DownVotes, Is.EqualTo(1)); + Assert.That(quote.NetVotes, Is.EqualTo(-1)); + } + + } +} diff --git a/Tests/VideoGameQuotes.Api.Tests/VideoGameQuotes.Api.Tests.csproj b/Tests/VideoGameQuotes.Api.Tests/VideoGameQuotes.Api.Tests.csproj new file mode 100644 index 0000000..cbfd208 --- /dev/null +++ b/Tests/VideoGameQuotes.Api.Tests/VideoGameQuotes.Api.Tests.csproj @@ -0,0 +1,77 @@ + ++ +NHibernate.Driver.MySqlDataDriver +Database=vgquotes;Data Source=localhost;User Id=vgquotes;Password=vgquotes +NHibernate.Dialect.MySQLDialect +NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu +true + ++ + \ No newline at end of file diff --git a/VideoGameQuotes.sln b/VideoGameQuotes.sln new file mode 100644 index 0000000..edefd4a --- /dev/null +++ b/VideoGameQuotes.sln @@ -0,0 +1,26 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VideoGameQuotes.Api", "Src\VideoGameQuotes.Api\VideoGameQuotes.Api.csproj", "{329FAB1F-A18D-4B7B-9E3C-A0C157E55503}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VideoGameQuotes.Api.Tests", "Tests\VideoGameQuotes.Api.Tests\VideoGameQuotes.Api.Tests.csproj", "{90FEE5DE-9A30-4A23-9A1E-14DABA0CF472}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {329FAB1F-A18D-4B7B-9E3C-A0C157E55503}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {329FAB1F-A18D-4B7B-9E3C-A0C157E55503}.Debug|Any CPU.Build.0 = Debug|Any CPU + {329FAB1F-A18D-4B7B-9E3C-A0C157E55503}.Release|Any CPU.ActiveCfg = Release|Any CPU + {329FAB1F-A18D-4B7B-9E3C-A0C157E55503}.Release|Any CPU.Build.0 = Release|Any CPU + {90FEE5DE-9A30-4A23-9A1E-14DABA0CF472}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {90FEE5DE-9A30-4A23-9A1E-14DABA0CF472}.Debug|Any CPU.Build.0 = Debug|Any CPU + {90FEE5DE-9A30-4A23-9A1E-14DABA0CF472}.Release|Any CPU.ActiveCfg = Release|Any CPU + {90FEE5DE-9A30-4A23-9A1E-14DABA0CF472}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal+ +Debug +AnyCPU +8.0.30703 +2.0 +{90FEE5DE-9A30-4A23-9A1E-14DABA0CF472} +Library +Properties +VideoGameQuotes.Api.Tests +VideoGameQuotes.Api.Tests +v4.0 +512 ++ +true +full +false +..\..\bin\Debug\ +DEBUG;TRACE +prompt +4 ++ +pdbonly +true +..\..\bin\Release\ +TRACE +prompt +4 ++ ++ +..\..\Lib\log4net.dll ++ +..\..\Lib\MySql.Data.dll ++ + +..\..\Lib\nunit.framework.dll ++ +..\..\Lib\Portoa.dll ++ + + + + + + + ++ + + + ++ +{329FAB1F-A18D-4B7B-9E3C-A0C157E55503} +VideoGameQuotes.Api ++ ++ + +