Permalink
Browse files

Properly removed Raven from baseline.

  • Loading branch information...
1 parent e52cb2f commit 074785b1b0a603750ab03142ca30e02c51fc0b02 @mslot committed Sep 10, 2012
Showing with 0 additions and 177 deletions.
  1. +0 −76 IRCSharp.Statistics.Kernel/Dal/RavenDal.cs
  2. +0 −101 UnitTest/RavenDal/AddQueryTest.cs
@@ -1,76 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace IRCSharp.Statistics.Kernel.Dal
-{
- public class RavenDal : IDal
- {
- private Raven.Client.Embedded.EmbeddableDocumentStore _documentStore = null;
- private Raven.Client.IDocumentSession _session;
-
- public RavenDal(string dataDirectory, bool useEmbeddedHttpServer = false, bool runInMemory = false)
- {
- InittializeDatastore(dataDirectory, useEmbeddedHttpServer, runInMemory);
- }
-
- private void InittializeDatastore(string dataDirectory, bool useEmbeddedHttpServer, bool runInMemory)
- {
- _documentStore = new Raven.Client.Embedded.EmbeddableDocumentStore { DataDirectory = dataDirectory, UseEmbeddedHttpServer = useEmbeddedHttpServer, RunInMemory = runInMemory };
- _documentStore.Initialize();
- }
-
- public void AddQuery(IRCSharp.Kernel.Model.Query.IRCCommandQuery query)
- {
- using (_session = _documentStore.OpenSession())
- {
- bool doesUserExist = _session.Query<Model.User>().Any(user => user.Nick == query.Nick);
- if (doesUserExist)
- {
- bool doesChannelExist = _session.Query<Model.User>().Any(user => user.Nick == query.Nick && user.Channels.Any(channel => channel.ChannelName == query.Channel));
- if (doesChannelExist)
- {
- //TODO: With partial update -> add query to channel
- Model.User user = GetUser(query.Nick);
- user.AddQuery(query);
- _session.Store(user);
- }
- else
- {
- Model.Channel newChannel = new Model.Channel(query.Channel);
- newChannel.Queries.Add(query);
- _documentStore.DatabaseCommands.Patch("users/" + query.Nick,
- new[]
- {
- new Raven.Abstractions.Data.PatchRequest
- {
- Type = Raven.Abstractions.Data.PatchCommandType.Add,
- Name = "Channels",
- Value = Raven.Json.Linq.RavenJObject.FromObject(newChannel)
- }
- });
- }
- }
- else
- {
- Model.User newUser = new Model.User(query.Nick);
- newUser.AddQuery(query);
- _session.Store(newUser);
- }
-
- _session.SaveChanges();
- }
- }
-
- public Model.User GetUser(string nick)
- {
- return _session.Load<Model.User>(nick);
- }
-
- public void Dispose()
- {
- _documentStore.Dispose();
- }
- }
-}
@@ -1,101 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using NUnit.Framework;
-
-namespace UnitTest.RavenDal
-{
- [TestFixture]
- class AddQueryTest
- {
- public IEnumerable<IRCSharp.Kernel.Model.Query.IRCCommandQuery> GenerateQueries()
- {
- LinkedList<IRCSharp.Kernel.Model.Query.IRCCommandQuery> queries = new LinkedList<IRCSharp.Kernel.Model.Query.IRCCommandQuery>();
- List<string> rawQueries = new List<string> {
- ":mslot1!~mslot1@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
- ":mslot1!~mslot1@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
- ":mslot1!~mslot1@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
- ":mslot1!~mslot1@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
- ":mslot1!~mslot1@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
- ":mslot1!~mslot1@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
- ":mslot1!~mslot1@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
- ":mslot1!~mslot1@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
- ":mslot2!~mslot2@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
- ":mslot2!~mslot2@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
- ":mslot2!~mslot2@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
- ":mslot2!~mslot2@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
- ":mslot2!~mslot2@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
- ":mslot2!~mslot2@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
- ":mslot2!~mslot2@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
- ":mslot2!~mslot2@56344eba.rev.stofanet.dk PRIVMSG #c :!command arg1 arg2 arg3",
- ":mslot2!~mslot2@56344eba.rev.stofanet.dk PRIVMSG #c :!command arg1 arg2 arg3",
- ":mslot2!~mslot2@56344eba.rev.stofanet.dk PRIVMSG #c :!command arg1 arg2 arg3",
- ":mslot2!~mslot2@56344eba.rev.stofanet.dk PRIVMSG #c :!command arg1 arg2 arg3",
- ":mslot2!~mslot2@56344eba.rev.stofanet.dk PRIVMSG #c :!command arg1 arg2 arg3",
- ":mslot2!~mslot2@56344eba.rev.stofanet.dk PRIVMSG #c :!command arg1 arg2 arg3",
- ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #c :!command arg1 arg2 arg3",
- ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
- ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
- ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
- ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
- ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
- ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
- ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
- ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
- ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
- ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
- ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
- ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
- ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
- ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
- ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
- ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #lol :!command arg1 arg2 arg3",
- ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #lol :!command arg1 arg2 arg3",
- ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #lol :!command arg1 arg2 arg3",
- ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #lol :!command arg1 arg2 arg3",
- ":mslot4!~mslot4@56344eba.rev.stofanet.dk PRIVMSG #lol :!command arg1 arg2 arg3",
- ":mslot4!~mslot4@56344eba.rev.stofanet.dk PRIVMSG #lol :!command arg1 arg2 arg3",
- ":mslot4!~mslot4@56344eba.rev.stofanet.dk PRIVMSG #lol :!command arg1 arg2 arg3",
- ":mslot4!~mslot4@56344eba.rev.stofanet.dk PRIVMSG #lol :!command arg1 arg2 arg3",
- ":mslot4!~mslot4@56344eba.rev.stofanet.dk PRIVMSG #lol :!command arg1 arg2 arg3",
- ":mslot4!~mslot4@56344eba.rev.stofanet.dk PRIVMSG #lol :!command arg1 arg2 arg3",
- ":mslot4!~mslot4@56344eba.rev.stofanet.dk PRIVMSG #lol :!command arg1 arg2 arg3",
- ":mslot4!~mslot4@56344eba.rev.stofanet.dk PRIVMSG #3 :!command arg1 arg2 arg3",
- ":mslot4!~mslot4@56344eba.rev.stofanet.dk PRIVMSG #3 :!command arg1 arg2 arg3",
- ":mslot4!~mslot4@56344eba.rev.stofanet.dk PRIVMSG #3 :!command arg1 arg2 arg3",
- ":mslot!~mslot@56344eba.rev.stofanet.dk PRIVMSG #error :!command arg1 arg2 arg3",
- ":mslot!~mslot@56344eba.rev.stofanet.dk PRIVMSG #error :!command arg1 arg2 arg3",
- ":mslot!~mslot@56344eba.rev.stofanet.dk PRIVMSG #error :!command arg1 arg2 arg3",
- ":mslot!~mslot@56344eba.rev.stofanet.dk PRIVMSG #error :!command arg1 arg2 arg3"
- };
-
- foreach (string rawQuery in rawQueries)
- {
- IRCSharp.Kernel.Model.Query.IRCCommandQuery query = null;
- bool parsed = IRCSharp.Kernel.Parser.IRC.IRCQueryParser.TryParse(rawQuery, out query);
- queries.AddLast(query);
- }
-
- return queries;
- }
-
-
- [Test]
- public void AddFirstGeneratedQueries()
- {
- var generatedQueries = GenerateQueries();
- IRCSharp.Kernel.Model.Query.IRCCommandQuery firstQuery = generatedQueries.First();
- using (IRCSharp.Statistics.Kernel.Dal.IDal _dal = new IRCSharp.Statistics.Kernel.Dal.RavenDal(@"C:\data\StatisticsRavenDalTest",
- useEmbeddedHttpServer: false,
- runInMemory: true)
- )
- {
- _dal.AddQuery(firstQuery);
- IRCSharp.Statistics.Kernel.Model.User user = _dal.GetUser(firstQuery.Nick);
- Assert.NotNull(user);
- }
-
- }
- }
-}

0 comments on commit 074785b

Please sign in to comment.