Ejemplo n.º 1
0
        public void StreamGetTest()
        {
            var managedPath = "Data" +
                              Path.DirectorySeparatorChar +
                              "create-file-get-stream-on-disposed.txt";

            var manager = new CreateNonEmptyFileManager(
                managedPath,
                overwrite: true);

            // Simulate a preparation

            Assert.AreEqual(false, FileManagerReflection.GetField(manager, "disposed"));

            FileStream stream = (FileStream)FileManagerReflection.Invoke(
                manager,
                "OnPrepareFileStream",
                new string[] { managedPath });

            FileManagerReflection.SetStream(manager, stream);

            // Dispose the manager
            manager.Dispose();

            ExceptionAssert.IsThrown(
                () => { var managerStream = manager.ManagedFileStream; },
                expectedType: typeof(ObjectDisposedException),
                expectedMessage: "Cannot access a disposed object." +
                Environment.NewLine +
                "Object name: " +
                "\'CreateNonEmptyFileManager\'."
                );
        }