{"id":187,"date":"2021-02-08T14:17:02","date_gmt":"2021-02-08T06:17:02","guid":{"rendered":"https:\/\/www.tonghin.com.my\/blog\/?p=187"},"modified":"2021-02-08T14:17:04","modified_gmt":"2021-02-08T06:17:04","slug":"fix-overall-bug-in-repository-and-view-model-class","status":"publish","type":"post","link":"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/08\/fix-overall-bug-in-repository-and-view-model-class\/","title":{"rendered":"Fix Overall Bug in Repository and View Model Class"},"content":{"rendered":"\n<p class=\"has-text-align-left\">First and foremost, I start the week by removing duplicate integrations tests. Then, fix failure tests on repository test class as all of it failed. It is fix by adding test_server config.xml file to map towards database. However, few tests on UOM (unit of measurement) failed. As the test class is testing actual database tests. Direct initialization is required to ensure function run throw the references, variable able to reach and store directed value.<br><br>Next, I have problem with state machine in the system. Upon deletion of selected data, the system would prompt error of state machine. <code><sub><sup>State.DeleteTrigger()<\/sup><\/sub><\/code> is not implemented to go to correct state next. Thus, the only way is to remove <code><sub><sup>State.DeleteTrigger()<\/sup><\/sub><\/code>. By removing <code><sub><sup>State.DeleteTrigger()<\/sup><\/sub><\/code>, the state machine would move from <code><sub><sup>State.SelectedTrigger()<\/sup><\/sub><\/code> to <code><sub><sup>State.DeselectTrigger()<\/sup><\/sub><\/code>, which is logical flow as mapped in State Machine class.<br><br>Repository class only handles database code which is CRUD command towards database. Thus, move business logic that wrongly implemented in repository class to Wrapper Service\/View Model class. After moving those logic away from repository class, the code in repository is more tidy.<br><br>Last but not least, I find it weird that system does not prompt error under a concurrency situation when It suppose to.  I ran through the system once and I found out problem occurs at my status checker from last week&#8217;s implementation. The value of <code><sub><sup>_selectedStatus<\/sup><\/sub><\/code> is set to <code><sub><sup>SelectedStatus.Normal<\/sup><\/sub><\/code>, which will constantly get latest data to update the list before I save any changes. <br><br><code><sub><sup>if (_selectedStatus == SelectedStatus.Normal)<br>{<br>  _selectedStatus = SelectedStatus.Selected;<br>  _eventAggregator.GetEvent().Publish(id); \/\/Get Latest Data<br>}<\/sup><\/sub><\/code><br><br>Hence, database update is smooth as if there is no concurrency situation. But it will make user think they did not make any changes, if both before and after value appears to be the same. To solve this, I define <code><sub><sup>_selectedStatus == SelectedStatus.Selected<\/sup><\/sub><\/code> before I request to save changes upon editing selected data, so that it does not pass through get latest data event.<br><\/p>\n\n\n\n<p>  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>First and foremost, I start the week by removing duplicate integrations tests. Then, fix failure tests on repository test class as all of it failed. It is fix by adding test_server config.xml file to map towards database. However, few tests on UOM (unit of measurement) failed. As the test class is testing actual database tests. &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/08\/fix-overall-bug-in-repository-and-view-model-class\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Fix Overall Bug in Repository and View Model Class&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[32,17],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v15.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Fix Overall Bug in Repository and View Model Class | Tong Hin&#039;s Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/08\/fix-overall-bug-in-repository-and-view-model-class\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Fix Overall Bug in Repository and View Model Class | Tong Hin&#039;s Blog\" \/>\n<meta property=\"og:description\" content=\"First and foremost, I start the week by removing duplicate integrations tests. Then, fix failure tests on repository test class as all of it failed. It is fix by adding test_server config.xml file to map towards database. However, few tests on UOM (unit of measurement) failed. As the test class is testing actual database tests. &hellip; Continue reading &quot;Fix Overall Bug in Repository and View Model Class&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/08\/fix-overall-bug-in-repository-and-view-model-class\/\" \/>\n<meta property=\"og:site_name\" content=\"Tong Hin&#039;s Blog\" \/>\n<meta property=\"article:published_time\" content=\"2021-02-08T06:17:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-02-08T06:17:04+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\">\n\t<meta name=\"twitter:data1\" content=\"2 minutes\">\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#organization\",\"name\":\"TONG HIN MACHINERY\",\"url\":\"https:\/\/www.tonghin.com.my\/blog\/\",\"sameAs\":[\"https:\/\/www.youtube.com\/channel\/UC60EoxJMNbu8mV0LuEGfrBg\"],\"logo\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#logo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/www.tonghin.com.my\/blog\/wp-content\/uploads\/2020\/10\/web_logo_180_180.jpg\",\"width\":180,\"height\":180,\"caption\":\"TONG HIN MACHINERY\"},\"image\":{\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#logo\"}},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#website\",\"url\":\"https:\/\/www.tonghin.com.my\/blog\/\",\"name\":\"Tong Hin&#039;s Blog\",\"description\":\"Sharing About Technology\",\"publisher\":{\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/www.tonghin.com.my\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/08\/fix-overall-bug-in-repository-and-view-model-class\/#webpage\",\"url\":\"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/08\/fix-overall-bug-in-repository-and-view-model-class\/\",\"name\":\"Fix Overall Bug in Repository and View Model Class | Tong Hin&#039;s Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#website\"},\"datePublished\":\"2021-02-08T06:17:02+00:00\",\"dateModified\":\"2021-02-08T06:17:04+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/08\/fix-overall-bug-in-repository-and-view-model-class\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/08\/fix-overall-bug-in-repository-and-view-model-class\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/08\/fix-overall-bug-in-repository-and-view-model-class\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/\",\"url\":\"https:\/\/www.tonghin.com.my\/blog\/\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"position\":2,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/08\/fix-overall-bug-in-repository-and-view-model-class\/\",\"url\":\"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/08\/fix-overall-bug-in-repository-and-view-model-class\/\",\"name\":\"Fix Overall Bug in Repository and View Model Class\"}}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/08\/fix-overall-bug-in-repository-and-view-model-class\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/08\/fix-overall-bug-in-repository-and-view-model-class\/#webpage\"},\"author\":{\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#\/schema\/person\/5c3ea1c3869fc5aace6be92e60cb5daa\"},\"headline\":\"Fix Overall Bug in Repository and View Model Class\",\"datePublished\":\"2021-02-08T06:17:02+00:00\",\"dateModified\":\"2021-02-08T06:17:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/08\/fix-overall-bug-in-repository-and-view-model-class\/#webpage\"},\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#organization\"},\"keywords\":\"repository pattern,tests\",\"articleSection\":\"Experiential\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/08\/fix-overall-bug-in-repository-and-view-model-class\/#respond\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#\/schema\/person\/5c3ea1c3869fc5aace6be92e60cb5daa\",\"name\":\"Ng Ching Onn\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5124ba2323631ad4d512f46bd9c04829?s=96&d=mm&r=g\",\"caption\":\"Ng Ching Onn\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/posts\/187"}],"collection":[{"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/comments?post=187"}],"version-history":[{"count":3,"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/posts\/187\/revisions"}],"predecessor-version":[{"id":194,"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/posts\/187\/revisions\/194"}],"wp:attachment":[{"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/media?parent=187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/categories?post=187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/tags?post=187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}