{"action":"closed","issue":{"url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/10606","repository_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore","labels_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/10606/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/10606/comments","events_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/10606/events","html_url":"https://github.com/aspnet/EntityFrameworkCore/issues/10606","id":284285403,"number":10606,"title":"EF Core 2.0 - InMemoryDatabase Testing - Changing a value of an attribute is Updating the database record","user":{"login":"JRBonnema","id":23283340,"avatar_url":"https://avatars3.githubusercontent.com/u/23283340?v=4","gravatar_id":"","url":"https://api.github.com/users/JRBonnema","html_url":"https://github.com/JRBonnema","followers_url":"https://api.github.com/users/JRBonnema/followers","following_url":"https://api.github.com/users/JRBonnema/following{/other_user}","gists_url":"https://api.github.com/users/JRBonnema/gists{/gist_id}","starred_url":"https://api.github.com/users/JRBonnema/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JRBonnema/subscriptions","organizations_url":"https://api.github.com/users/JRBonnema/orgs","repos_url":"https://api.github.com/users/JRBonnema/repos","events_url":"https://api.github.com/users/JRBonnema/events{/privacy}","received_events_url":"https://api.github.com/users/JRBonnema/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-12-23T04:30:59Z","updated_at":"2017-12-27T23:19:58Z","closed_at":"2017-12-27T23:19:58Z","author_association":"NONE","body":"I observed what I consider unexpected behaviour when doing integration testing using InMemoryDatabase testing. It seems that line 4 in the TestMethod below is actually updating the database record from OPEN to CLOSED. It was intended to be only a preparation for the actual update using the repository that for simplicity I have left out here. I'm aware that quote \"InMemory is designed to be a general purpose database for testing, and is not designed to mimic a relational database\", but in my opinion this behaviour is not what I expect from a general purpose database. I would like to hear from you if you consider this a bug. If not how can I test my update procedures using InMemoryDatabase ?\r\n\r\n```C#\r\n        [TestMethod]\r\n        public void Authors_ChangeStatusCode_StrangeBehaviour()\r\n        {\r\n            Author authToBeUpdated = _repository.getAuthor(\"Postma\");\r\n            Guid internalCode = authToBeUpdated.InternalCode;\r\n            Assert.IsTrue(authToBeUpdated.StatusCode == \"OPEN\");\r\n\r\n        4)  authToBeUpdated.StatusCode = \"CLOSED\";\r\n\r\n            Author authFound1 = _repository.get(authToBeUpdated.InternalCode);\r\n            Assert.IsTrue(authFound1.StatusCode == \"CLOSED\");\r\n            Author authFound2 = _repository.getAuthor(authToBeUpdated.Name);\r\n            Assert.IsTrue(authFound2.StatusCode == \"CLOSED\");\r\n        }\r\n```\r\n        Part of creating the record - works correctly.\r\n```C#\r\n        private Author createAuthorRecord(string authorName, string externalCode)\r\n        {\r\n            Author auth = new Author();\r\n            auth.InternalCode = Guid.NewGuid();\r\n            auth.ExternalCode = externalCode;\r\n            auth.StatusCode = \"OPEN\";\r\n            auth.Name = authorName;\r\n\r\n           ....\r\n\r\n            return auth;\r\n        }\r\n```\r\n      Base class for constructing the  .UseInMemoryDatabase\r\n\r\n```C#\r\n      public abstract class AbstractTestBase\r\n      {\r\n        protected readonly BooksDbContext _testDbContext;\r\n\r\n        public AbstractTestBase()\r\n        {\r\n            DbContextOptions<BooksDbContext> _options\r\n                = new DbContextOptionsBuilder<BooksDbContext>()\r\n                        .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())\r\n                        .Options;\r\n\r\n            _testDbContext = new BooksDbContext(_options);\r\n            _testDbContext.Database.EnsureCreated();\r\n        }\r\n\r\n        public virtual void Dispose()\r\n        {\r\n            _testDbContext.Database.EnsureDeleted();\r\n            _testDbContext.Dispose();\r\n        }\r\n```\r\n\r\n### Further technical details\r\nEF Core version: 2.0.1\r\nDatabase Provider: InMemoryDatabase\r\nOperating system: Windows 10\r\nIDE: (e.g. Visual Studio 2017 15.5.2)\r\n"}}
{"actor":{"display_login":"ajcvickers"}}