public void Save_Error_ValuesIncrement()
        {
            ErrorMapper errorMapper = new ErrorMapper(this.client, this.database);
            Guid applicationId = Guid.NewGuid();
            Guid deviceId = Guid.NewGuid();

            ErrorSummary expected = new ErrorSummary()
            {
                ApplicationId = applicationId,
                Count = 2,
                Date = date,
                PlatformId = platform,
                Version = version,
                ScreenErrors = new List<Aggregate<string>>()
                {
                     new Aggregate<string>()
                     {
                          Key = "someScreen",
                          Count = 2
                     }
                }
            };

            ErrorSummary summary = new ErrorSummary()
            {
                ApplicationId = applicationId,
                Count = 1,
                Date = date,
                PlatformId = platform,
                Version = version,
                ScreenErrors = new List<Aggregate<string>>()
                {
                     new Aggregate<string>("someScreen")
                }
            };

            errorMapper.Save(summary);
            errorMapper.Save(summary);

            IMongoQuery query = Query.And
                (
                    Query<ErrorSummary>.EQ<DateTime>(mem => mem.Date, date),
                    Query<ErrorSummary>.EQ<Guid>(mem => mem.ApplicationId, applicationId),
                    Query<ErrorSummary>.EQ<string>(mem => mem.Version, version),
                    Query<ErrorSummary>.EQ<PlatformType>(mem => mem.PlatformId, platform)
                );

            ErrorSummary actual = this.GetCollection<ErrorSummary>().FindOne(query);

            actual.ShouldHave().AllPropertiesBut(x => x.Id)
                .IncludingNestedObjects().EqualTo(expected);
        }
        public void Save(ErrorSummary entity)
        {
            try
            {
                IMongoQuery queryBase = Query.And
                    (
                        Query<ErrorSummary>.EQ<DateTime>(mem => mem.Date, entity.Date),
                        Query<ErrorSummary>.EQ<Guid>(mem => mem.ApplicationId, entity.ApplicationId),
                        Query<ErrorSummary>.EQ<string>(mem => mem.Version, entity.Version),
                        Query<ErrorSummary>.EQ<PlatformType>(mem => mem.PlatformId, entity.PlatformId)
                    );

                IMongoUpdate update = Update<ErrorSummary>
                    .SetOnInsert(x => x.Version, entity.Version)
                    .SetOnInsert(x => x.Date, entity.Date)
                    .SetOnInsert(x => x.ApplicationId, entity.ApplicationId)
                    .SetOnInsert(x => x.PlatformId, entity.PlatformId)
                    .SetOnInsert(x => x.ScreenErrors, new List<Aggregate<string>>())
                    .Inc(mem => mem.Count, entity.Count);

                this.GetCollection<ErrorSummary>().FindAndModify(queryBase, SortBy.Descending("Date"), update, false, true);
                this.GetCollection<ErrorSummary>().EnsureIndex(IndexKeys.Descending("Date"));

                IMongoQuery queryNotExists = Query.And
                    (
                        queryBase,
                        Query.NE("ScreenErrors.Key", BsonValue.Create(entity.ScreenErrors.First().Key))
                    );

                IMongoUpdate insertScreenError = Update
                    .Push("ScreenErrors", entity.ScreenErrors.First().CopyOnlyKeys().ToBsonDocument());

                this.GetCollection<ErrorSummary>().Update(queryNotExists, insertScreenError);

                IMongoQuery queryErrors = Query.And
                    (
                        queryBase,
                        Query.EQ("ScreenErrors.Key", BsonValue.Create(entity.ScreenErrors.First().Key))
                    );

                IMongoUpdate updateErrors = Update
                    .Inc("ScreenErrors.$.Count", 1);

                this.GetCollection<ErrorSummary>().Update(queryErrors, updateErrors);
            }
            catch (Exception ex)
            {
                throw new DataAccessLayerException(ex);
            }
        }
        public void Log(Error error)
        {
            Application application = this.applicationRepository.Find(error.ApplicationId);

            if (application != null)
            {
                DeviceInfo device = this.deviceRepository.Find(error.DeviceId);

                if (device != null)
                {
                    error.Add(device);

                    ErrorSummary errorSummary = new ErrorSummary(error);

                    this.errorRepository.Save(error);
                    this.errorRepository.Save(errorSummary);
                }
                else
                {
                    throw new NoDeviceException(error.DeviceId);
                }
            }
            else
            {
                throw new InactiveApplicationException(error.ApplicationId);
            }
        }
 public void Save(ErrorSummary entity)
 {
     this.errorMapper.Save(entity);
 }