public async Task Updates_soft_interruption_status() { await SetupSchedules(softInterruptionUpdaterDue : true); await DatabaseHelpers.CreateConfiguration(new Dictionary <string, string> { { "nearbyDistance", "3.5" }, { "shortLeadTimeSpaces", "0" }, { "totalSpaces", "0" } }); await DatabaseHelpers.CreateTrigger(); await DatabaseHelpers.CreateUser( CreateUser.With(userId: "User1", emailAddress: "*****@*****.**")); // Current instant is defined such that the next daily summary date is 02-Mar-2021 await DatabaseHelpers.CreateRequests( "User1", "2021-03", new Dictionary <string, string> { { "02", "P" } }); await TaskRunner.RunTasksAsync(CustomProviderFactory.CreateServiceProvider()); var savedRequests = await DatabaseHelpers.ReadRequests("User1", "2021-03"); Assert.Equal(new[] { "02" }, savedRequests.Keys); Assert.Equal("S", savedRequests["02"]); }
public async Task SetProfileForeColorAsync(EventContext e) { using (var context = new MikiContext()) { User user = await DatabaseHelpers.GetUserAsync(context, e.Author); var x = Regex.Matches(e.Arguments.ToString().ToUpper(), "(#)?([A-F0-9]{6})"); if (x.Count > 0) { ProfileVisuals visuals = await ProfileVisuals.GetAsync(e.Author.Id, context); var hex = x.First().Groups.Last().Value; visuals.ForegroundColor = hex; user.RemoveCurrency(250); await context.SaveChangesAsync(); e.SuccessEmbed($"Your foreground color has been successfully changed to `{hex}`") .QueueToChannel(e.Channel); } else { new EmbedBuilder() .SetTitle("🖌 Setting a foreground color!") .SetDescription("Changing your foreground(text) color costs 250 mekos. use `>setfrontcolor (e.g. #00FF00)` to purchase") .ToEmbed().QueueToChannel(e.Channel); } } }
private async Task ConfirmBuyMarriageSlot(EventContext cont, int costForUpgrade) { using (var context = new MikiContext()) { User user = await DatabaseHelpers.GetUserAsync(context, cont.Author); if (user.Currency >= costForUpgrade) { user.MarriageSlots++; user.Currency -= costForUpgrade; new EmbedBuilder() { Color = new Color(0.4f, 1f, 0.6f), Description = cont.Locale.GetString("buymarriageslot_success", user.MarriageSlots), }.ToEmbed().QueueToChannel(cont.Channel); await context.SaveChangesAsync(); await cont.EventSystem.GetCommandHandler <SessionBasedCommandHandler>().RemoveSessionAsync(cont.Author.Id, cont.Channel.Id); } else { new EmbedBuilder() { Color = new Color(1, 0.4f, 0.6f), Description = cont.Locale.GetString("buymarriageslot_insufficient_mekos", (costForUpgrade - user.Currency)), }.ToEmbed().QueueToChannel(cont.Channel); await cont.EventSystem.GetCommandHandler <SessionBasedCommandHandler>().RemoveSessionAsync(cont.Author.Id, cont.Channel.Id); } } }
/// <summary> /// First init /// </summary> private void Init() { // Set rpogramstate to running ProgramState.IsRunning = true; // Read the config files on startup ConfigFileHelpers.ReadServerConfigFile(); // Try to connect to the server Task.Run(async() => { await ProgramState.ServerConnection.ConnectAsync(); await DatabaseHelpers.Init(); }); // Set the current screen CurrentScreen = MainPages.WellcomeScreen; // The await does not work for some f****** reason! while (DatabaseHelpers.AllProducts == null) { ; } // Set this VM VM = this; }
public async Task SetProfileBackColorAsync(CommandContext e) { var context = e.GetService <MikiDbContext>(); User user = await DatabaseHelpers.GetUserAsync(context, e.Author); var x = Regex.Matches(e.Arguments.Pack.TakeAll().ToUpper(), "(#)?([A-F0-9]{6})"); if (x.Count > 0) { ProfileVisuals visuals = await ProfileVisuals.GetAsync(e.Author.Id, context); var hex = x.First().Groups.Last().Value; visuals.BackgroundColor = hex; user.RemoveCurrency(250); await context.SaveChangesAsync(); await e.SuccessEmbed($"Your foreground color has been successfully changed to `{hex}`") .QueueToChannelAsync(e.Channel); } else { await new EmbedBuilder() .SetTitle("🖌 Setting a background color!") .SetDescription("Changing your background color costs 250 mekos. use `>setbackcolor (e.g. #00FF00)` to purchase") .ToEmbed().QueueToChannelAsync(e.Channel); } }
public void TestGetStoredProcedureDoesNotLoadFunction() { string createProcedureStatement = GetProcedureStatement(this.connectionType); string createFunctionStatement = GetFunctionStatement(this.connectionType); DatabaseObjectCreation.CreateTestTable("CREATE TABLE TestTable ( IntValue INT )", this.connectionType); DatabaseObjectCreation.CreateTestProc(createProcedureStatement, this.connectionType); DatabaseObjectCreation.CreateTestFunction(createFunctionStatement, this.connectionType); try { DatabaseAssistant databaseAssistant = DatabaseAssistant.GetDatabaseAssistant(this.connectionType); using (var connection = databaseAssistant.CreateConnection(DatabaseHelpers.GetDefaultConnectionString(this.connectionType))) { connection.Open(); Assert.IsTrue(databaseAssistant.GetStoredProcedureNames(connection).Any(p => p.Contains("Test Proc"))); Assert.IsFalse(databaseAssistant.GetStoredProcedureNames(connection).Any(p => p.Contains("TestFunction"))); } } finally { DatabaseObjectCreation.RemoveTestProc(this.connectionType); DatabaseObjectCreation.RemoveTestFunction(this.connectionType); DatabaseObjectCreation.RemoveTestTable(this.connectionType); } }
private static ApplicationDatabase GetDatabase_1() { return(DatabaseHelpers.GetDatabase(a => { a.BlockChain.Add(new Block() { BlockHashPrevious = "GENESIS", BlockHash = "BLOCK_1", Length = 1, IsInMainChain = true }); a.SaveChanges(); a.BlockChain.Add(new Block() { BlockHashPrevious = "BLOCK_1", BlockHash = "BLOCK_2", Length = 2, IsInMainChain = true }); a.SaveChanges(); a.BlockChain.Add(new Block() { BlockHashPrevious = "BLOCK_2", BlockHash = "BLOCK_3", Length = 3 }); a.SaveChanges(); a.BlockChain.Add(new Block() { BlockHashPrevious = "BLOCK_1", BlockHash = "BLOCK_4", Length = 2 }); a.SaveChanges(); })); }
public void TestExecuteResultSetRowByRowWithCustomType() { var parameters = DatabaseObjectCreation.CreateResultSetTestProc(this.connectionType); try { var customType = TypeReference.CreateGeneratedType(new TypeProperty("Name", typeof(string))); var resultSet = new DatabaseModel.ResultSet { CustomType = customType }; resultSet.Fields.Add(new DatabaseModel.ResultSetField("Counter", DatabaseModel.DataType.Int32, string.Empty)); resultSet.Fields.Add(new DatabaseModel.ResultSetField("StringValue", DatabaseModel.DataType.String, "Name")); FunctionResult result = Execute(this.connectionType, DatabaseHelpers.GetDefaultConnectionString(this.connectionType), "Test Proc", parameters, new object[] { 2 }, new DatabaseModel.ResultSets { resultSet }, OutputOption.RowByRow); var executionPathResults = result.ExecutionPathResult.ToList(); Assert.AreEqual(2, executionPathResults.Count()); Assert.AreEqual("Result", executionPathResults[0].Name); Assert.AreEqual(Names.GetValidName(customType.Name), executionPathResults[0].Value.GetType().Name); Assert.AreEqual("one", executionPathResults[0].Value.Name); Assert.AreEqual("two", executionPathResults[1].Value.Name); } finally { DatabaseObjectCreation.RemoveTestProc(this.connectionType); } }
public void TestExecuteResultSetsRowByRow() { var parameters = DatabaseObjectCreation.CreateResultSetsTestProc(this.connectionType); try { FunctionResult result = Execute(this.connectionType, DatabaseHelpers.GetDefaultConnectionString(this.connectionType), "Test Proc", parameters, null, true, OutputOption.RowByRow); var executionPathResults = result.ExecutionPathResult.ToList(); Assert.AreEqual(3, executionPathResults.Count()); Assert.AreEqual("Result1", executionPathResults[0].Name); var row = executionPathResults[0].Value; Assert.AreEqual(1, row.Counter); Assert.AreEqual("one", row.StringValue); Assert.AreEqual("Result1", executionPathResults[1].Name); row = executionPathResults[1].Value; Assert.AreEqual(2, row.Counter); Assert.AreEqual("two", row.StringValue); Assert.AreEqual("Result2", executionPathResults[2].Name); row = executionPathResults[2].Value; Assert.AreEqual("qwer", row.StringValue); } finally { DatabaseObjectCreation.RemoveTestProc(this.connectionType); } }
public async Task Allocates_requests() { await SetupSchedules(); await DatabaseHelpers.CreateTrigger(); await DatabaseHelpers.CreateUser( CreateUser.With(userId: "User1", emailAddress: "*****@*****.**")); await DatabaseHelpers.CreateRequests( "User1", "2021-03", new Dictionary <string, string> { { "01", "I" } }); await TaskRunner.RunTasksAsync(CustomProviderFactory.CreateServiceProvider()); var savedRequests = await DatabaseHelpers.ReadRequests("User1", "2021-03"); Assert.Equal(new[] { "01" }, savedRequests.Keys); Assert.Equal("A", savedRequests["01"]); await CheckSingleEmail("*****@*****.**", "Parking space allocated for Mon 01 Mar"); }
public async Task Sends_daily_summary_email() { await SetupSchedules(dailyNotificationDue : true); await DatabaseHelpers.CreateTrigger(); await DatabaseHelpers.CreateConfiguration(new Dictionary <string, string> { { "nearbyDistance", "3.5" }, { "shortLeadTimeSpaces", "0" }, { "totalSpaces", "0" } }); await DatabaseHelpers.CreateUser( CreateUser.With(userId: "User1", emailAddress: "*****@*****.**")); // Current instant is defined such that the next daily summary date is 02-Mar-2021 await DatabaseHelpers.CreateRequests( "User1", "2021-03", new Dictionary <string, string> { { "02", "I" } }); await TaskRunner.RunTasksAsync(CustomProviderFactory.CreateServiceProvider()); await CheckSingleEmail("*****@*****.**", "Parking status for Tue 02 Mar: INTERRUPTED"); }
public async Task PreProcesses_requests() { await SetupSchedules(); await DatabaseHelpers.CreateConfiguration(new Dictionary <string, string> { { "nearbyDistance", "3.5" }, { "shortLeadTimeSpaces", "0" }, { "totalSpaces", "0" } }); await DatabaseHelpers.CreateTrigger(); await DatabaseHelpers.CreateUser( CreateUser.With(userId: "User1", emailAddress: "*****@*****.**")); await DatabaseHelpers.CreateRequests( "User1", "2021-03", new Dictionary <string, string> { { "02", "P" } }); await TaskRunner.RunTasksAsync(CustomProviderFactory.CreateServiceProvider()); var savedRequests = await DatabaseHelpers.ReadRequests("User1", "2021-03"); Assert.Equal(new[] { "02" }, savedRequests.Keys); Assert.Equal("I", savedRequests["02"]); }
private static async Task SetupSchedules( bool dailyNotificationDue = false, bool requestReminderDue = false, bool reservationReminderDue = false, bool softInterruptionUpdaterDue = false, bool weeklyNotificationDue = false) { const string DueTime = "2020-01-01T00:00:00Z"; const string NotDueTime = "2030-01-01T00:00:00Z"; var dailyNotificationTime = dailyNotificationDue ? DueTime : NotDueTime; var requestReminderTime = requestReminderDue ? DueTime : NotDueTime; var reservationReminderTime = reservationReminderDue ? DueTime : NotDueTime; var softInterruptionUpdaterTime = softInterruptionUpdaterDue ? DueTime : NotDueTime; var weeklyNotificationTime = weeklyNotificationDue ? DueTime : NotDueTime; var rawScheduleData = new Dictionary <string, string> { { "DAILY_NOTIFICATION", dailyNotificationTime }, { "REQUEST_REMINDER", requestReminderTime }, { "RESERVATION_REMINDER", reservationReminderTime }, { "SOFT_INTERRUPTION_UPDATER", softInterruptionUpdaterTime }, { "WEEKLY_NOTIFICATION", weeklyNotificationTime } }; await DatabaseHelpers.CreateSchedules(rawScheduleData); }
private static async Task SetupConfiguration() => await DatabaseHelpers.CreateConfiguration(new Dictionary <string, string> { { "nearbyDistance", "3.5" }, { "shortLeadTimeSpaces", "2" }, { "totalSpaces", "9" } });
/// <summary> /// Functie care insereaza un film in baza de date si verifica daca inserarea a avut loc cu succes. /// </summary> /// <param name="movie"></param> private static void InsertMovieAndCheckIfMovieExists(Movie movie) { // Deschid conexiunea in using. Conexiunea se inchide automat cand se termina blocul using. using (NpgsqlConnection npgsqlConnection = DatabaseHelpers.GetConn()) { // Inserez un film in baza de date InsertMovie(movie, npgsqlConnection); NpgsqlCommand npgsqlSelectCommand = SelectMovieCommand(movie, npgsqlConnection); // Deschid un sql reader si execut comanda de selectare a filmului using (NpgsqlDataReader npgsqlDataReader = npgsqlSelectCommand.ExecuteReader()) { // Daca un film in sql reader, exists = true, altfel exists = false. bool exists = npgsqlDataReader.Read(); // Daca filmul nu a fost selectat inseamna ca nu exista in baza de date if (!exists) { Assert.Fail(); } } } }
public void TestExecuteResultSetsListOfRows() { var parameters = DatabaseObjectCreation.CreateResultSetsTestProc(this.connectionType); try { var result = Execute(this.connectionType, DatabaseHelpers.GetDefaultConnectionString(this.connectionType), "Test Proc", parameters, null, true, OutputOption.ListOfRows).Value; Assert.AreEqual(2, result.Result1Rows.Count); var row = result.Result1Rows[0]; Assert.AreEqual(1, row.Counter); Assert.AreEqual("one", row.StringValue); row = result.Result1Rows[1]; Assert.AreEqual(2, row.Counter); Assert.AreEqual("two", row.StringValue); Assert.AreEqual(1, result.Result2Rows.Count); row = result.Result2Rows[0]; Assert.AreEqual("qwer", row.StringValue); } finally { DatabaseObjectCreation.RemoveTestProc(this.connectionType); } }
public void TestGetResultSetsForStoredProcedureWithDynamicSQL() { string createProcedureStatement = GetProcedureWithDynamicSQL(this.connectionType); DatabaseObjectCreation.CreateTestProc(createProcedureStatement, this.connectionType); DatabaseModel.ResultSets resultSets = null; try { DatabaseAssistant databaseAssistant = DatabaseAssistant.GetDatabaseAssistant(this.connectionType); using (var connection = databaseAssistant.CreateConnection(DatabaseHelpers.GetDefaultConnectionString(this.connectionType))) { connection.Open(); Assert.IsTrue(databaseAssistant.GetStoredProcedureNames(connection).Any(p => p.Contains("Test Proc"))); resultSets = databaseAssistant.GetResultSets(connection, "Test Proc"); } } finally { DatabaseObjectCreation.RemoveTestProc(this.connectionType); } Assert.AreEqual(1, resultSets.Count); var fields = resultSets[0].Fields; Assert.AreEqual(1, fields.Count); var field = fields[0]; Assert.AreEqual("Rowcount_Returned", field.ColumnName); Assert.AreEqual("Rowcount_Returned", field.OutputName); }
public void TestExecuteParameterAndResultSetsRowByRow() { var parameters = DatabaseObjectCreation.CreateParameterAndResultSetsTestProc(this.connectionType); try { List <byte> bytes = new List <byte>(new byte[] { 1, 2, 3, 4, 5 }); FunctionResult result = Execute(this.connectionType, DatabaseHelpers.GetDefaultConnectionString(this.connectionType), "Test Proc", parameters, new object[] { 2, 1.0, "Qwer", string.Empty, new DateTime(1987, 1, 24), DatabaseModel.DefaultDateTime, bytes, new List <byte>() }, true, OutputOption.RowByRow); var executionPathResults = result.ExecutionPathResult.ToList(); Assert.AreEqual(3, executionPathResults.Count()); Assert.AreEqual("Result1", executionPathResults[0].Name); var row = executionPathResults[0].Value; Assert.AreEqual("qwer", row.StringValue); Assert.AreEqual("Result2", executionPathResults[1].Name); row = executionPathResults[1].Value; Assert.AreEqual(1, row.Counter); Assert.AreEqual("Qwer", row.StringValue); row = executionPathResults[2].Value; Assert.AreEqual(2, row.Counter); Assert.AreEqual("Qwer", row.StringValue); Assert.AreEqual("Qwer", result.Value.ResultParameters.StringValueOut); Assert.AreEqual(new DateTime(1987, 1, 24), result.Value.ResultParameters.DateValueOut); Assert.AreEqual(bytes, result.Value.ResultParameters.BytesValueOut); } finally { DatabaseObjectCreation.RemoveTestProc(this.connectionType); } }
private static DbDataAdapter GetAdapter(ConnectionType connectionType, string connectionString, string sqlText, string[] parameterValues) { DbDataAdapter adapter = null; switch (connectionType) { case ConnectionType.SqlServer: adapter = new SqlDataAdapter(); break; case ConnectionType.Odbc: adapter = new OdbcDataAdapter(); break; case ConnectionType.OleDb: adapter = new OleDbDataAdapter(); break; case ConnectionType.Oracle: adapter = new OracleDataAdapter(); break; } adapter.SelectCommand = (DbCommand)DatabaseHelpers.CreateCommand(connectionType, connectionString, sqlText, parameterValues, 60); return(adapter); }
public void TestExecuteParameterAndResultSetsFirstRow( [Values(OutputOption.FirstRow, OutputOption.FirstRowElseEmptyRow)] OutputOption outputOption) { var parameters = DatabaseObjectCreation.CreateParameterAndResultSetsTestProc(this.connectionType); try { List <byte> bytes = new List <byte>(new byte[] { 1, 2, 3, 4, 5 }); var result = Execute(this.connectionType, DatabaseHelpers.GetDefaultConnectionString(this.connectionType), "Test Proc", parameters, new object[] { 2, 1.0, "Qwer", string.Empty, new DateTime(1987, 1, 24), DatabaseModel.DefaultDateTime, bytes, new List <byte>() }, true, outputOption).Value; Assert.AreEqual("Qwer", result.ResultParameters.StringValueOut); Assert.AreEqual(new DateTime(1987, 1, 24), result.ResultParameters.DateValueOut); Assert.AreEqual(bytes, result.ResultParameters.BytesValueOut); Assert.AreEqual("qwer", result.Result1.StringValue); Assert.AreEqual(1, result.Result2.Counter); Assert.AreEqual("Qwer", result.Result2.StringValue); } finally { DatabaseObjectCreation.RemoveTestProc(this.connectionType); } }
public async Task InitializeDatabaseAlbumExistsExceptionTest() { using (var container = Substitute.For <UnityContainer>()) { var dataAccess = Substitute.For <IDataAccess>(); dataAccess.OpenOrCreateDatabaseAsync().Returns(DatabaseState.New); dataAccess.ExecuteSqlWithParametersAsync(Arg.Any <string>(), Arg.Any <List <SQLiteParameter> >()).Returns(0); dataAccess.ExecuteQueryWithParametersAsync(Arg.Any <string>(), Arg.Any <List <SQLiteParameter> >()).Returns(a => (ICursor)null); container.RegisterInstance(Resources.DataAccessObjectName, dataAccess, new ContainerControlledLifetimeManager()); container.RegisterType <AlbumController>(new InjectionFactory(s => new AlbumController(dataAccess))); container.RegisterType <ArtistController>(new InjectionFactory(s => new ArtistController(dataAccess))); container.RegisterType <GenreController>(new InjectionFactory(s => new GenreController(dataAccess))); container.RegisterType <StatisticsController>(new InjectionFactory(s => new StatisticsController(dataAccess))); try { await DatabaseHelpers.InitializeDatabase(container); } catch (Exception ex) { Assert.IsInstanceOf <SQLiteException>(ex); Assert.AreEqual($"unknown error\r\n{Resources.AlbumExistsExceptionMessage}", ex.Message); } } }
public void InsertOkMovieTest() { // Arrange - creez un film Movie movie = new Movie { MovieId = Guid.NewGuid().ToString(), Title = "movie-title-insert-ok-test", Description = "movie-description-insert-ok-test" }; // Act - folosesc functia pe care vrea sa o testez IMoviesRepository moviesRepository = new MoviesRepository(DatabaseHelpers.GetContext()); IResult <Movie> result = moviesRepository.Insert(movie); // Assert switch (result) { case OK <Movie> ok: Assert.AreEqual(movie.MovieId, ok.Result.MovieId); Assert.AreEqual(movie.Title, ok.Result.Title); Assert.AreEqual(movie.Description, ok.Result.Description); break; case Error <Movie> error: Console.WriteLine(error.Message); break; default: throw new NotImplementedException(); } }
static void Main(string[] args) { List <SeasonData> seasons = new List <SeasonData>(); Console.WriteLine("Starting Legacy Extractions"); seasons = GetAllSeasons(); //seasons = GetOneShlSeason(22); Console.WriteLine("----"); Console.WriteLine("Uploading Data to DB"); DatabaseHelpers.AddLeagues(); DatabaseHelpers.AddSeasonTypes(); foreach (var season in seasons) { Console.Write(" - Season " + season.SourceSeason.Number); season.SaveDataToDB(); Console.Write(" [DONE]"); Console.WriteLine(); } DatabaseHelpers.AddFranchises(); DatabaseHelpers.RemoveExtraPlayers(); Console.WriteLine("----"); Console.WriteLine("Extraction Complete"); Console.WriteLine(); }
public void InsertMovieWithNullIdTest() { // Act Movie movie = new Movie() { MovieId = null, Title = "movie-ttitle-insert-nullid-test", Description = "movie-description-insert-nullid-test" }; // Arrange IMoviesRepository moviesRepository = new MoviesRepository(DatabaseHelpers.GetContext()); var result = moviesRepository.Insert(movie); // Assert switch (result) { case OK <Movie> ok: Assert.Fail(); break; case Error <Movie> error: Assert.AreEqual(error.Message, "Id is null."); break; default: throw new NotImplementedException(); } }
public void CreateTemporalTable() { using (var context = DatabaseHelpers.CreateContext()) { // Arrange/Act var id = Guid.NewGuid(); context.People.Add(new Context.Person { Id = id, Name = "Dazza" }); context.SaveChanges(); var person = context.People.SingleOrDefault(x => x.Id == id); person.Name = "MadDawg"; context.SaveChanges(); // Assert var historic = context.People.FromSql("SELECT * FROM [dbo].[People_History]").ToList(); Assert.IsTrue(context.People.Any()); Assert.IsTrue(historic.Any()); } }
public void DeleteMovieTest() { // Arrange Movie movie = new Movie() { MovieId = Guid.NewGuid().ToString(), Title = "movie-title-delete-movie-test", Description = "movie-description-deletemovie-test" }; // Verific sa vad daca filmul este in baza de date InsertMovieAndCheckIfMovieExists(movie); // Act IMoviesRepository moviesRepository = new MoviesRepository(DatabaseHelpers.GetContext()); IResult <Movie> deleteResult = moviesRepository.Delete(movie); // Assert switch (deleteResult) { case OK <Movie> ok: Assert.AreEqual(movie.MovieId, ok.Result.MovieId); Assert.AreEqual(movie.Title, ok.Result.Title); Assert.AreEqual(movie.Description, ok.Result.Description); break; case Error <Movie> error: Console.WriteLine(error.Message); break; default: throw new NotImplementedException(); } }
private async Task InternalCheckAsync(BasePacket packet) { long userId = packet.discordUser.Id.ToDbLong(); using (var context = new MikiContext()) { Achievement a = await DatabaseHelpers.GetAchievementAsync(context, userId, Name); if (a == null) { if (await Achievements[0].CheckAsync(packet)) { await AchievementManager.Instance.UnlockAsync(Achievements[0], packet.discordChannel, packet.discordUser); await AchievementManager.Instance.CallAchievementUnlockEventAsync(Achievements[0], packet.discordUser, packet.discordChannel); } return; } if (a.Rank >= Achievements.Count - 1) { return; } if (await Achievements[a.Rank + 1].CheckAsync(packet)) { await AchievementManager.Instance.UnlockAsync(Achievements[a.Rank + 1], packet.discordChannel, packet.discordUser, a.Rank + 1); await AchievementManager.Instance.CallAchievementUnlockEventAsync(Achievements[a.Rank + 1], packet.discordUser, packet.discordChannel); } } }
public void UpdateMovieWithNullIdTest() { // Arrange Movie movie = new Movie() { MovieId = Guid.NewGuid().ToString(), Title = "movie-update-movieid-withnull-test", Description = "movie-update-movieid-withnull-test" }; InsertMovieAndCheckIfMovieExists(movie); movie = null; // Act IMoviesRepository moviesRepository = new MoviesRepository(DatabaseHelpers.GetContext()); IResult <Movie> updateResult = moviesRepository.Update(movie); // Assert switch (updateResult) { case OK <Movie> ok: Assert.Fail(); break; case Error <Movie> error: Assert.AreEqual(error.Message, "Movie is required."); break; default: throw new NotImplementedException(); } }
public void GetHeadBlockQuery_Should_Return_Block_With_The_Longest_Length_When_More_Exists_Longest() { var dbContext = DatabaseHelpers.GetDatabase(a => { a.BlockChain.Add(new Block() { BlockHashPrevious = "GENESIS", BlockHash = "BLOCK_1", Length = 1 }); a.SaveChanges(); a.BlockChain.Add(new Block() { BlockHashPrevious = "BLOCK_1", BlockHash = "BLOCK_2", Length = 2 }); a.SaveChanges(); a.BlockChain.Add(new Block() { BlockHashPrevious = "BLOCK_1", BlockHash = "BLOCK_3", Length = 2 }); a.SaveChanges(); }); var query = new GetHeadBlockQueryHandler(dbContext); var block = query.Handle(new GetHeadBlockQuery() { }); Assert.True(block.BlockHash == "BLOCK_2" || block.BlockHash == "BLOCK_3"); Assert.True(block.Length == 2); Assert.True(block.BlockHashPrevious == "BLOCK_1"); }
public void Save() { var collection = DatabaseHelpers.GetSeedCollection(); var filter = Builders <Evolution> .Filter.Eq(s => s.Id, this.Id); collection.ReplaceOne(filter, this); }