public void RefreshGenomeStatsCache_UpdatesCache_WhenInvokedAndCacheAlreadyExists()
        {
            var rOptions = TestDbContextOptionsFactory.GetTestReadDbOptions();
            var cOptions = TestDbContextOptionsFactory.GetTestCommandDbOptions();

            using var readContext    = new ReadGenomeContext(rOptions);
            using var commandContext = new CommandGenomeContext(cOptions);
            var testGenomes = new List <Genome>()
            {
                new Genome(new[] { "ACGT", "TGCA" }, false),
                new Genome(new[] { "AAAA", "BBBB" }, true),
            };

            readContext.Genomes.AddRange(testGenomes);
            readContext.SaveChanges();
            var testStats = new StatsModel()
            {
                Id          = 1,
                HumanCount  = 1,
                MutantCount = 0,
                Ratio       = 0,
                Changed     = DateTime.UtcNow.AddDays(-1)
            };

            commandContext.StatsModels.Add(testStats);
            commandContext.SaveChanges();
            var statsRepository = new StatsRepository(readContext, commandContext);

            statsRepository.RefreshGenomeStatsCache();
            var result = commandContext.StatsModels.Find(1);

            Assert.Equal(1, result.HumanCount);
            Assert.Equal(1, result.MutantCount);
            Assert.Equal(0.5, result.Ratio);
        }
Exemple #2
0
        public void CreateGenome_DoesInsertNewGenome_WhenItDoesntExistInDb()
        {
            var rOptions = TestDbContextOptionsFactory.GetTestReadDbOptions();
            var cOptions = TestDbContextOptionsFactory.GetTestCommandDbOptions();

            using var commandContext = new CommandGenomeContext(cOptions);
            using var readContext    = new ReadGenomeContext(rOptions);
            var testGenome       = new Genome(new[] { "AA", "GG" }, false);
            var genomeRepository = new GenomeRepository(commandContext, readContext);

            var result = genomeRepository.CreateGenome(testGenome);

            Assert.True(result.Result, "'CreateGenome' method did not insert a row, but it should have");
        }
        public void GetStats_ReturnsCorrectStatsModel_WhenInvokedWithNoData()
        {
            var rOptions = TestDbContextOptionsFactory.GetTestReadDbOptions();
            var cOptions = TestDbContextOptionsFactory.GetTestCommandDbOptions();

            using var readContext    = new ReadGenomeContext(rOptions);
            using var commandContext = new CommandGenomeContext(cOptions);
            var statsRepository = new StatsRepository(readContext, commandContext);

            var result = statsRepository.GetGenomeStats();

            Assert.Equal(0, result.HumanCount);
            Assert.Equal(0, result.MutantCount);
            Assert.Equal(0, result.Ratio);
        }
Exemple #4
0
        public void CreateGenome_DoesNotInsertGenome_WhenItAlreadyExistsInDb()
        {
            var rOptions = TestDbContextOptionsFactory.GetTestReadDbOptions();
            var cOptions = TestDbContextOptionsFactory.GetTestCommandDbOptions();

            using var readContext    = new ReadGenomeContext(rOptions);
            using var commandContext = new CommandGenomeContext(cOptions);
            var testGenome = new Genome(new[] { "AC", "GT" }, false);

            commandContext.Genomes.Add(testGenome);
            commandContext.SaveChanges();
            var genomeRepository = new GenomeRepository(commandContext, readContext);

            var result = genomeRepository.CreateGenome(testGenome);

            Assert.False(result.Result, "'CreateGenome' method inserted a row, but it shouldn't have");
        }
        public void GetStats_ReturnsCorrectStatsModel_WhenInvokedWithOnlyOneMutantRow()
        {
            var rOptions = TestDbContextOptionsFactory.GetTestReadDbOptions();
            var cOptions = TestDbContextOptionsFactory.GetTestCommandDbOptions();

            using var readContext    = new ReadGenomeContext(rOptions);
            using var commandContext = new CommandGenomeContext(cOptions);
            var testGenomes = new List <Genome>()
            {
                new Genome(new[] { "ACGT", "TGCA" }, true),
            };

            readContext.Genomes.AddRange(testGenomes);
            readContext.SaveChanges();
            var statsRepository = new StatsRepository(readContext, commandContext);

            var result = statsRepository.GetGenomeStats();

            Assert.Equal(0, result.HumanCount);
            Assert.Equal(1, result.MutantCount);
            Assert.Equal(1, result.Ratio);
        }
        public void RefreshGenomeStatsCache_LoadsCache_WhenInvokedAndCacheDoesNotExist()
        {
            var rOptions = TestDbContextOptionsFactory.GetTestReadDbOptions();
            var cOptions = TestDbContextOptionsFactory.GetTestCommandDbOptions();

            using var readContext    = new ReadGenomeContext(rOptions);
            using var commandContext = new CommandGenomeContext(cOptions);
            var testGenomes = new List <Genome>()
            {
                new Genome(new[] { "ACGT", "TGCA" }, false),
                new Genome(new[] { "AAAA", "BBBB" }, true),
            };

            readContext.Genomes.AddRange(testGenomes);
            readContext.SaveChanges();
            var statsRepository = new StatsRepository(readContext, commandContext);

            statsRepository.RefreshGenomeStatsCache();
            var result = commandContext.StatsModels.Find(1);

            Assert.Equal(1, result.HumanCount);
            Assert.Equal(1, result.MutantCount);
            Assert.Equal(0.5, result.Ratio);
        }