public void ProcessCommandImportTest() { var mockContactOperations = new MockDb(); var mockXmlReader = new MockXmlReader(); string output; ContactImporter.ContactOperations = mockContactOperations; ContactImporter.XmlContactReader = mockXmlReader; ContactImporter.ProcessCommand("Import mock", out output); var expectedOutput = $"Inserted Contacts : {3}. Duplicate Contacts : {1}"; Assert.AreEqual(expectedOutput, output); }
public void ProcessCommandReadTest() { var mockContactOperations = new MockDb(); mockContactOperations.ContactsList.AddRange(new List<Contact>() { new Contact() { Id = new ObjectId(), PhoneNumbers = { "02163162577", "05367369622" }, FirstName = "Kyle", LastName = "Katarn" }, new Contact() { Id = new ObjectId(), PhoneNumbers = { "02163162577", "12321415" }, FirstName = "R2", LastName = "D2" }, new Contact() { Id = new ObjectId(), PhoneNumbers = { "0", "1" }, FirstName = "Jon", LastName = "Osterman" }} ); string output; ContactImporter.ContactOperations = mockContactOperations; ContactImporter.ProcessCommand("Read R2", out output); var expectedOutput = ""; ContactImporter.CreateContactText(mockContactOperations.ContactsList[1], ref expectedOutput); Assert.AreEqual(expectedOutput, output); }
public override MyEntityResponse <bool> DeleteById(int id) { var myEntityResponse = GetById(id); // db.Set<T>().Attach(myEntityResponse.Single); // db.Entry(myEntityResponse.Single).State = EntityState.Deleted; // db.SaveChanges(); var em = GetQuery().First(e => e.Id == id); var l = GetQuery().ToList(); l.Remove(em); MockDb.SetNewList <T>(l); return(new MyEntityResponse <bool> { Single = true }); }
public async void Test_Create_Invalid_Visitor_TimeOut() { //Arrange var db = MockDb.CreateMockDb(); var c = new VisitorsController(db); var visitor = new Visitor { FirstName = "Alex", LastName = "Coa", PhoneNumber = "6476666888", ParkingId = 5, TimeOfEntry = System.DateTime.Today }; c.ModelState.AddModelError("Description", "MaxWords(4)"); //Act var r = await c.Create(visitor); //Assert var result = Assert.IsType <ViewResult>(r); var model = Assert.IsAssignableFrom <Visitor>(result.ViewData.Model); Assert.Equal(visitor, model); Assert.IsType <SelectList>(result.ViewData["parkingId"]); }
public void PostNews_ThatIsIncorrect_ShouldThorw400BadRequeis() { var news = MockDb.News(); var mockRepo = new Mock <IRepository <News> >(); mockRepo.Setup(n => n.Add(It.IsAny <News>())).Callback((News n) => news.Add(n)); var controller = new NewsController(mockRepo.Object); SetupController(controller, "news"); var bindigModel = new NewsBindingModel() { Content = "...", PublishedDate = DateTime.Now.ToString("D") }; var result = controller.PostNews(bindigModel).ExecuteAsync(new CancellationToken()).Result; Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode); }
public void EditNews_ThatDoesNotExists_ShouldReturn400BadRequest() { var news = MockDb.News(); var mockRepo = new Mock <IRepository <News> >(); mockRepo.Setup(n => n.Update(It.IsAny <News>())).Callback((News n) => news[IncorrectNewsId - 1] = n); var controller = new NewsController(mockRepo.Object); SetupController(controller, "news"); var bindigModel = new NewsBindingModel() { Title = "Vremeto", Content = "...", PublishedDate = DateTime.Now.ToString("D") }; var result = controller.EditMock(IncorrectNewsId, bindigModel).ExecuteAsync(new CancellationToken()).Result; Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode); }
public void ShouldMapTableNameForChild() { // db config var conn = new MockDb() .NewReader("Field1") .NewRow(1); using (conn) using (var db = new DbManager(conn)) { // fluent config new FluentMap <TableNameDbo>() .TableName("TableNameDboT1") .MapTo(db); // when db.GetTable <TableNameChildDbo>().ToArray(); // then conn.Commands[0] .Assert().AreTable("TableNameDboT1", "Fail mapping"); } }
public void ShouldMapNonUpdatableForChild() { // db config var conn = new MockDb() .NewNonQuery(); using (conn) using (var db = new DbManager(conn)) { // fluent config new FluentMap <NonUpdatableDbo>() .NonUpdatable(_ => _.Field1) .MapTo(db); // when new SqlQuery <NonUpdatableChildDbo>(db).Insert(new NonUpdatableChildDbo { Field1 = 10, Field2 = 1 }); // then Assert.AreEqual(1, conn.Commands[0].Parameters.Count, "Fail params"); } }
public void Initialize() { var db = new MockDb(new[] { new Node(1, "Varna"), new Node(2, "Sofia"), new Node(3, "Plovdiv"), }, new[] { new Edge(1, 2), new Edge(2, 3), new Edge(3, 1), }); this.controller = new NodesController( new MockGetNodesQuery(db), new MockCreateNodeCommand(), new MockGetNodeByIdQuery(db), new MockUpdateNodeCommand(), new MockDeleteNodeCommand(), new MockGetLogisticCenterIdQuery() ); }
public ContactForSponsorEdit_Tests() { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); _config = builder.Build(); var testLibrary = _config.GetValue <string>("TestLibrary"); if (testLibrary == "Mock") { MockDb.ResetMockDb(); } else { if (!IsDatabaseBuilt) { var adoDb = new ADODb(); adoDb.BuildMemberManagerADODb(); IsDatabaseBuilt = true; } } }
public override MyEntityResponse <int> Save(T model) { var entities = GetQuery().ToList(); T newEntity; if (model.Id == 0) { model.Id = new Random().Next(); entities.Add(model); newEntity = model; } else { var entity = entities.FirstOrDefault(e => e.Id == model.Id); if (entity == null) { throw new Exception("رکورد یافت نشد"); } entities.Remove(entity); entities.Add(model); //db.Entry(entity).CurrentValues.SetValues(model); } MockDb.SetNewList <T>(entities); // db.SaveChanges(); // db.Entry(model).State = EntityState.Detached; return(new MyEntityResponse <int> { Single = model.Id }); }
public void ShouldMapField() { // db config var conn = new MockDb() .NewNonQuery(); using (conn) using (var db = new DbManager(conn)) { // fluent config new FluentMap <MapFieldDbo>() .MapField(_ => _.Field1, "f1") .MapTo(db); // when db.GetTable <MapFieldDbo>().Insert(() => new MapFieldDbo { Field1 = 1 }); // then conn.Commands[0] .Assert().AreField("f1", "Fail mapping"); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); MockDb.Seed(app); }
public void ShouldMapTrimmableForChild() { // db config var conn = new MockDb() .NewReader("Field1") .NewRow("test "); using (conn) using (var db = new DbManager(conn)) { // fluent config new FluentMap <TrimmableDbo>() .Trimmable(_ => _.Field1) .MapTo(db); var table = db.GetTable <TrimmableChildDbo>(); // when var dbo = (from t in table select t).First(); // then Assert.AreEqual("test", dbo.Field1, "Not trimmable"); } }
public void SetupTests() { MockDb.InitializeData(); _Adapter = new MockCustomerDataAdapter(); }
public void Retrieve_Database() { MockDb.LoadData(MockDb.Users); }
public override IQueryable <T> GetQuery() { return(MockDb.MyDb <T>().AsQueryable()); }
public EmployeesController() { db = PopulateDb(); }
public void Initialize() { MockDb mock = new MockDb(); #region Records #region User mock.UserList.Add(new User(true, "Hrafn", "Hrafn Orri Hrafnkelsson", 1994, Gender.MALE, "*****@*****.**", 1)); mock.UserList.Add(new User(true, "Gudni", "Gudni Fannar Kristjánsson", 1994, Gender.MALE, "*****@*****.**", 2)); mock.UserList.Add(new User(false, "Kristinn", "Kristinn Þorri Þrastarsson", 1989, Gender.MALE, "*****@*****.**", 3)); mock.UserList.Add(new User(true, "Helgi", "Helgi Rúnar Einarsson", 1989, Gender.MALE, "*****@*****.**", 4)); mock.UserList.Add(new User(true, "Fanney", "Fanney Sigurðardóttir", 1985, Gender.FEMALE, "*****@*****.**", 5)); #endregion #region Group mock.Groups.Add(new Group(true, 1, "Lan Group", 1)); mock.Groups.Add(new Group(true, 1, "MVC Project", 2)); mock.Groups.Add(new Group(true, 2, "Bobby Tables", 3)); mock.Groups.Add(new Group(false, 1, "HearthStone For Live", 4)); mock.Groups.Add(new Group(true, 2, "Runescape fanatics", 5)); mock.Groups.Add(new Group(true, 3, "Ghost in the machine", 6)); mock.Groups.Add(new Group(false, 3, "Ghost birthdays", 7)); mock.Groups.Add(new Group(false, 4, "Sports for live", 8)); #endregion #region Event mock.Events.Add(new Event(true, null, 5, "Sund", "Non", "FAra í sund og fá okkur ís", new DateTime(), new DateTime(), 30, "Kópavogi", 1, 2, 1)); mock.Events.Add(new Event(true, 8, 3, "Fotbolti", "Non1", "Taka smá fótbolta með Braga", new DateTime(), new DateTime(), 30, "Garðabæ", 1, 2, 2)); mock.Events.Add(new Event(true, 1, 1, "Lan", "Non2", "Taka nokkra aom heima hjá hrafni", new DateTime(), new DateTime(), 30, "Kópavogi", 1, 2, 3)); mock.Events.Add(new Event(true, 1, 2, "RuneScape", "Non3", "Mine some ores", new DateTime(), new DateTime(), 30, "Akureyri", 1, 2, 4)); mock.Events.Add(new Event(true, 1, 2, "League Of Legends", "Non4", "Taka ap darius", new DateTime(), new DateTime(), 30, "Kópavogi", 1, 2, 5)); mock.Events.Add(new Event(false, 1, 1, "HearthStone", "Non5", "Spila smá aggro warrior", new DateTime(), new DateTime(), 30, "Kópavogi", 1, 2, 6)); mock.Events.Add(new Event(true, 1, 5, "Heroes of the storm", "Non6", "Feed Lili", new DateTime(), new DateTime(), 30, "Hafnafyrði", 1, 2, 7)); mock.Events.Add(new Event(true, 8, 4, "Korfubolti", "Non7", "Shoot some hoops", new DateTime(), new DateTime(), 30, "Kópavogi", 1, 2, 8)); mock.Events.Add(new Event(false, 8, 4, "Golf", "Non8", "Spila 18 holur", new DateTime(), new DateTime(), 30, "Garðabæ", 1, 2, 9)); mock.Events.Add(new Event(true, 2, 3, "Database", "Non9", "Halda áfram með databasið", new DateTime(), new DateTime(), 30, "Kópavogi", 1, 2, 10)); #endregion #region Comment mock.Comments.Add(new Comment(true, 1, "First1", new DateTime(1,1,1), 1)); mock.Comments.Add(new Comment(true, 1, "First2", new DateTime(1,1,1), 2)); mock.Comments.Add(new Comment(true, 1, "First3", new DateTime(1,1,1), 3)); mock.Comments.Add(new Comment(false, 2, "Second", new DateTime(2, 2, 2), 4)); #endregion #endregion #region Relations #region UserToUser mock.UserToUserRelations.Add(new UserToUserRelation(true, 1, 2, true, 1)); mock.UserToUserRelations.Add(new UserToUserRelation(true, 1, 3, true, 2)); mock.UserToUserRelations.Add(new UserToUserRelation(true, 1, 4, true, 3)); mock.UserToUserRelations.Add(new UserToUserRelation(false, 1, 5, false, 4)); mock.UserToUserRelations.Add(new UserToUserRelation(true, 1, 5, false, 4)); mock.UserToUserRelations.Add(new UserToUserRelation(true, 2, 3, null, 5)); #endregion #region GroupToUserRelation mock.GroupToUserRelations.Add(new GroupToUserRelation(true, 1, 1, 1)); mock.GroupToUserRelations.Add(new GroupToUserRelation(true, 1, 2, 2)); mock.GroupToUserRelations.Add(new GroupToUserRelation(true, 1, 5, 2)); mock.GroupToUserRelations.Add(new GroupToUserRelation(true, 2, 1, 3)); mock.GroupToUserRelations.Add(new GroupToUserRelation(true, 2, 2, 4)); mock.GroupToUserRelations.Add(new GroupToUserRelation(true, 2, 3, 5)); mock.GroupToUserRelations.Add(new GroupToUserRelation(true, 2, 4, 6)); mock.GroupToUserRelations.Add(new GroupToUserRelation(true, 2, 5, 7)); mock.GroupToUserRelations.Add(new GroupToUserRelation(true, 3, 1, 8)); mock.GroupToUserRelations.Add(new GroupToUserRelation(false, 4, 1, 9)); mock.GroupToUserRelations.Add(new GroupToUserRelation(true, 5, 2, 10)); mock.GroupToUserRelations.Add(new GroupToUserRelation(true, 6, 3, 11)); mock.GroupToUserRelations.Add(new GroupToUserRelation(true, 6, 1, 12)); mock.GroupToUserRelations.Add(new GroupToUserRelation(true, 6, 2, 13)); mock.GroupToUserRelations.Add(new GroupToUserRelation(false, 7, 2, 14)); mock.GroupToUserRelations.Add(new GroupToUserRelation(false, 7, 2, 15)); mock.GroupToUserRelations.Add(new GroupToUserRelation(true, 7, 2, 16)); #endregion #region GroupToEventRelation mock.GroupToEventRelations.Add(new GroupToEventRelation(true, 8, 2, 1)); mock.GroupToEventRelations.Add(new GroupToEventRelation(true, 1, 3, 2)); mock.GroupToEventRelations.Add(new GroupToEventRelation(true, 1, 4, 3)); mock.GroupToEventRelations.Add(new GroupToEventRelation(true, 1, 5, 4)); mock.GroupToEventRelations.Add(new GroupToEventRelation(true, 1, 6, 5)); mock.GroupToEventRelations.Add(new GroupToEventRelation(true, 1, 7, 6)); mock.GroupToEventRelations.Add(new GroupToEventRelation(true, 8, 8, 7)); mock.GroupToEventRelations.Add(new GroupToEventRelation(true, 8, 9, 8)); mock.GroupToEventRelations.Add(new GroupToEventRelation(false, 2, 10, 1)); mock.GroupToEventRelations.Add(new GroupToEventRelation(true, 2, 10, 9)); mock.GroupToEventRelations.Add(new GroupToEventRelation(true, 0, 0, 1)); mock.GroupToEventRelations.Add(new GroupToEventRelation(true, 1, 1, 1)); mock.GroupToEventRelations.Add(new GroupToEventRelation(true, 88, 90, 1)); mock.GroupToEventRelations.Add(new GroupToEventRelation(true, -1, 2, 1)); #endregion #region EventToUserRelation mock.EventToUserRelations.Add(new EventToUserRelation(true, 3, 1, true, 1)); mock.EventToUserRelations.Add(new EventToUserRelation(false, 4, 1, true, 2)); mock.EventToUserRelations.Add(new EventToUserRelation(true, 4, 1, false, 3)); mock.EventToUserRelations.Add(new EventToUserRelation(true, 6, 1, true, 4)); mock.EventToUserRelations.Add(new EventToUserRelation(true, 5, 1, true, 5)); mock.EventToUserRelations.Add(new EventToUserRelation(true, 1, 2, null, 1)); mock.EventToUserRelations.Add(new EventToUserRelation(true, 3, 2, true, 1)); mock.EventToUserRelations.Add(new EventToUserRelation(true, 4, 2, true, 1)); mock.EventToUserRelations.Add(new EventToUserRelation(true, 5, 2, false, 1)); mock.EventToUserRelations.Add(new EventToUserRelation(true, 7, 2, true, 1)); #endregion #region EventToCommentRelation mock.EventToCommentRelations.Add(new EventToCommentRelation(false, 1, 2, 1)); mock.EventToCommentRelations.Add(new EventToCommentRelation(true, 1, 2, 2)); mock.EventToCommentRelations.Add(new EventToCommentRelation(true, 6, 1, 3)); mock.EventToCommentRelations.Add(new EventToCommentRelation(true, 1, 2, 4)); mock.EventToCommentRelations.Add(new EventToCommentRelation(true, 1, 2, 5)); mock.EventToCommentRelations.Add(new EventToCommentRelation(false, 10, 1, 6)); mock.EventToCommentRelations.Add(new EventToCommentRelation(false, 9, 3, 7)); mock.EventToCommentRelations.Add(new EventToCommentRelation(false, 9, 4, 8)); mock.EventToCommentRelations.Add(new EventToCommentRelation(false, 9, 5, 9)); #endregion #endregion db = new Database(mock); }
public void SetupTests() { MockDb.InitializeData(); _Adapter = new MockReviewDataAdapter(); }
public PieRepository(MockDb mockDb) { _mockDb = mockDb; }
public static AssertDb Assert(this MockDb db) { return(new AssertDb(db)); }
public MockImp(ServiceType service) : base(null) { MockDb.GetTypeTable <T>(service.GetMocklist()); }
public void SetUp() { _target = new MockDb(); }
public void Initialize() { MockDb mock = new MockDb(); #region Users User user1 = new User { UserID = 1, Active = true, UserName = "******", DisplayName = "xXx$w4gM4$t3r420xXx", BirthYear = 9000, Gender = Gender.MALE, Email = "[email protected]" }; User user2 = new User { UserID = 2, Active = true, UserName = "******", DisplayName = "Sultumenni500", BirthYear = 1337, Gender = Gender.MALE, Email = "*****@*****.**" }; User user3 = new User { UserID = 3, Active = true, UserName = "******", DisplayName = "Pulsmeister99", BirthYear = 9000, Gender = Gender.FEMALE, Email = "*****@*****.**" }; mock.UserList.Add(user1); mock.UserList.Add(user2); mock.UserList.Add(user3); #endregion #region Groups Group group1 = new Group { GroupID = 1, Active = true, OwnerId = 1, Name = "Team Gulli" }; Group group2 = new Group { GroupID = 2, Active = true, OwnerId = 3, Name = "Pulsuvagninn" }; mock.Groups.Add(group1); mock.Groups.Add(group2); #endregion #region Events Event event1 = new Event { EventID = 1, Active = true, GroupId = null, OwnerId = 1, Name = "Lan", Photo = "", Description = "Quake 4 lyfe", CreationTime = new DateTime(2015, 5, 6, 12, 30, 1), TimeOfEvent = new DateTime(2015, 5, 9, 12, 30, 0), Minutes = 60, Location = "the internet", Min = 0, Max = 5, }; Event event2 = new Event { EventID = 2, Active = true, GroupId = 2, OwnerId = 3, Name = "Pulsuparty", Photo = "", Description = "pulsulíf", CreationTime = new DateTime(2015, 5, 6, 12, 30, 1), TimeOfEvent = new DateTime(2015, 5, 9, 12, 30, 0), Minutes = 60, Location = "bæjarins bestu", Min = 0, Max = 5, }; mock.Events.Add(event1); mock.Events.Add(event2); #endregion #region Comments Comment comment1 = new Comment { CommentID = 1, Active = true, OwnerId = 2, Content = "FOKK PULSUR, SULTA IS SUPERIOR", CreationTime = new DateTime(2015, 5, 6, 12, 35, 1) }; mock.Comments.Add(comment1); #endregion #region GroupToUserRelations GroupToUserRelation groupUser1 = new GroupToUserRelation { GroupToUserRelationID = 1, Active = true, GroupId = 1, MemberId = 1 }; GroupToUserRelation groupUser2 = new GroupToUserRelation { GroupToUserRelationID = 2, Active = true, GroupId = 2, MemberId = 3 }; GroupToUserRelation groupUser3 = new GroupToUserRelation { GroupToUserRelationID = 3, Active = true, GroupId = 2, MemberId = 2 }; GroupToUserRelation groupUser4 = new GroupToUserRelation { GroupToUserRelationID = 4, Active = true, GroupId = 1, MemberId = 2 }; mock.GroupToUserRelations.Add(groupUser1); mock.GroupToUserRelations.Add(groupUser2); mock.GroupToUserRelations.Add(groupUser3); mock.GroupToUserRelations.Add(groupUser4); #endregion #region GroupsToEventRelations GroupToEventRelation groupEvent1 = new GroupToEventRelation { GroupToEventRelationID = 1, Active = true, EventId = 2, GroupId = 2 }; mock.GroupToEventRelations.Add(groupEvent1); #endregion #region UserToUserRelations UserToUserRelation friendship1 = new UserToUserRelation { UserToUserRelationID = 1, Active = true, SenderId = 2, ReceiverId = 3, Answer = true }; UserToUserRelation friendship2 = new UserToUserRelation { UserToUserRelationID = 2, Active = true, SenderId = 1, ReceiverId = 2, Answer = true }; mock.UserToUserRelations.Add(friendship1); mock.UserToUserRelations.Add(friendship2); #endregion #region EventToUserRelations EventToUserRelation eventUser1 = new EventToUserRelation { EventToUserRelationID = 1, Active = true, EventId = 1, AttendeeId = 1, Answer = true }; EventToUserRelation eventUser2 = new EventToUserRelation { EventToUserRelationID = 2, Active = true, EventId = 1, AttendeeId = 2, Answer = null }; EventToUserRelation eventUser3 = new EventToUserRelation { EventToUserRelationID = 3, Active = true, EventId = 2, AttendeeId = 3, Answer = true }; EventToUserRelation eventUser4 = new EventToUserRelation { EventToUserRelationID = 4, Active = true, EventId = 2, AttendeeId = 2, Answer = false }; mock.EventToUserRelations.Add(eventUser1); mock.EventToUserRelations.Add(eventUser2); mock.EventToUserRelations.Add(eventUser3); mock.EventToUserRelations.Add(eventUser4); #endregion #region EventToCommentRelations EventToCommentRelation eventComment1 = new EventToCommentRelation { EventToCommentRelationID = 1, EventId = 2, CommentId = 1, Active = true }; mock.EventToCommentRelations.Add(eventComment1); #endregion DbTest = new Database(mock); ServiceTest = new Service(DbTest); }
public void ShouldMapRelation() { // given List <Parent> parents = new List <Parent>(); MapResultSet[] sets = new MapResultSet[3]; sets[0] = new MapResultSet(typeof(Parent), parents); sets[1] = new MapResultSet(typeof(Child)); sets[2] = new MapResultSet(typeof(Grandchild)); // db config var conn = new MockDb() .NewReader("ParentID") .NewRow(1) .NewRow(2) .NextResult("ChildID", "ParentID") .NewRow(4, 1) .NewRow(5, 2) .NewRow(6, 2) .NewRow(7, 1) .NextResult("GrandchildID", "ChildID") .NewRow(1, 4) .NewRow(2, 4) .NewRow(3, 5) .NewRow(4, 5) .NewRow(5, 6) .NewRow(6, 6) .NewRow(7, 7) .NewRow(8, 7); using (conn) using (var db = new DbManager(conn)) { // fluent config new FluentMap <Parent>() .MapField(_ => _.ID, "ParentID").PrimaryKey() .MapField(_ => _.Children).Relation() .MapTo(db); new FluentMap <Child>() .MapField(_ => _.Parent.ID, "ParentID") .MapField(_ => _.ID, "ChildID").PrimaryKey() .MapField(_ => _.Parent).Relation() .MapField(_ => _.Grandchildren).Relation() .MapTo(db); new FluentMap <Grandchild>() .MapField(_ => _.Child.ID, "ChildID") .MapField(_ => _.ID, "GrandchildID").PrimaryKey() .MapField(_ => _.Child).Relation() .MapTo(db); // when db.SetCommand("select *").ExecuteResultSet(sets); } // then Assert.IsTrue(parents.Any()); foreach (Parent parent in parents) { Assert.IsNotNull(parent); Assert.IsTrue(parent.Children.Any()); foreach (Child child in parent.Children) { Assert.AreEqual(parent, child.Parent); Assert.IsTrue(child.Grandchildren.Any()); foreach (Grandchild grandchild in child.Grandchildren) { Assert.AreEqual(child, grandchild.Child); Assert.AreEqual(parent, grandchild.Child.Parent); } } } }
static void Main(string[] args) { // loop to continue until user is done - key q string _input = ""; UserDTO user = new UserDTO(); //bool IsFound = false; MockDb db = new MockDb(); string _connection = ConfigurationManager.ConnectionStrings["DBCONN"].ToString(); string _database = ConfigurationManager.AppSettings["MOCKORDB"].ToString(); DbAdo ado = new DbAdo(_connection); Printer.MainMenu(); _input = Console.ReadLine().ToLower(); do { // enter app as a guest if (_input.ToLower() == "g") { user = new UserDTO(RoleType.Guest); } if (_input.ToLower() == "pp") { Printer.Profile(user); } if (_input.ToLower() == "pu") { List <UserDTO> _users = new List <UserDTO>();; if (_database == DBType.Mock.ToString()) { _users = db.GetUsers(); } else { // database version _users = ado.GetUsers(); } Printer.Users(_users); // TODO: implement this } if (_input.ToLower() == "pr") { // TODO: can I make the configurable?? List <RoleDTO> _roles; if (_database == DBType.Mock.ToString()) { _roles = db.GetRoles(); } else { _roles = ado.GetRoles(); } Printer.Roles(_roles); // TODO: implement this } if (_input.ToLower() == "pm") { Printer.MainMenu(); } if (_input.ToLower() == "r") // REGISTER { UserDTO u = Printer.CollectAddUserData(); if (_database == DBType.Mock.ToString()) { db.CreateUser(u); } else { // database version ado.CreateUser(u); } } // else if(input.ToLower() == "l") // LOGIN // { // // login method and , where to go next ?? // // WHAT ARE THE LOGICAL STEPS FOR LOGGING IN? // // step 1: prompt for username and password // // step 2a: retrieve all users and put that in variable - GetUsers() // // step 2b: loop thru the users list, checking username/password from the list // // step 2c: compare username and password for current element in the loop // // step 2d: if match, log them in and save the info // // step 2f: error message, bad login and prompt to enter again // Console.WriteLine("Enter your username: "******"Enter your password: "******"Match found. Welcome {0} {1}. Your Role is {2}.", loginInUser.FirstName, // loginInUser.LastName, loginInUser.Role.RoleName); // IsFound = true; // } // } // if (IsFound == false) { // Console.WriteLine("User incorrect. Try again."); // } // // depending on the Role, we will want to provide a custom set of menu options // // PATRON - least privileges // // CHECKOUT STUFF // // menu - search, update my profile, logout // if (loginInUser.RoleID_FK == (int)Roles.Patron) // PATRON ROLE // { // Console.WriteLine("MENU: S - Search, P - My Profile, O - Logout"); // string inputPatron = Console.ReadLine(); // if (inputPatron.ToLower() == "o") // { // IsFound = false; // without this - a bug that caused an infinite loop // Console.WriteLine("Logging out .... Bye {0} {1}", loginInUser.FirstName, loginInUser.LastName); // continue; // } // else // { // Printer.PatronOptions(inputPatron, loginInUser); // } // } // else if(loginInUser.RoleID_FK == (int)Roles.Librarian) // LIBRARIAN ROLE // { // Console.WriteLine("MENU: S - Search, P - My Profile, B - Book, A - Author, " + // " P - Publisher, G - Genre, O - Logout"); // string inputLibrarian = Console.ReadLine(); // if (inputLibrarian.ToLower() == "o") // { // IsFound = false; // without this - a bug that caused an infinite loop // Console.WriteLine("Logging out .... Bye {0} {1}", loginInUser.FirstName, loginInUser.LastName); // continue; // } // else // { // Printer.LibrarianOptions(inputLibrarian, loginInUser); // } // } // else if (loginInUser.RoleID_FK == (int)Roles.Administrator) // ADMINISTRATOR ROLE // { // Console.WriteLine("MENU: S - Search, P - My Profile, B - Book, A - Author, " + // " P - Publisher, G - Genre, U - User, O - Logout"); // string inputAdmin = Console.ReadLine(); // if (inputAdmin.ToLower() == "o") // { // IsFound = false; // without this - a bug that caused an infinite loop // Console.WriteLine("Logging out .... Bye {0} {1}", loginInUser.FirstName, loginInUser.LastName); // continue; // } // else // { // Printer.AdminOptions(inputAdmin, loginInUser); // } // } // // ADMINSTRATOR - most privieges // // CHANGE PASSWORD, RESETTING STUFF // // menu - search, update my profile, Book, Publisher, Genre, Users logout // } Printer.MainMenu(); _input = Console.ReadLine().ToLower(); } while (_input.ToLower() != "q"); Printer.End(); Console.ReadLine(); // stop program }